dongzhuner6981 2014-04-10 15:00
浏览 52
已采纳

更改wp_list_categories的链接路径

I output the subcategories of the category Fruit via this code:

<?php  $category = get_category_by_slug('fruit'); 
wp_list_categories('hide_empty=1&depth=1&title_li=&child_of='.$category->term_id); ?> 

It will output the subcategories correctly.

Apples = domain.com/fruit/apples 
Oranges = domain.com/fruit/oranges

However, specifically for the Oranges, i would like the link to go to custom page which i created:

domain.com/orange-page/

and not to the default of domain.com/fruit/oranges

Is there a way to make a rule within the wp_list_categories to modify the link for that one listing?

  • 写回答

1条回答 默认 最新

  • dsieyx2015 2014-04-10 15:04
    关注

    As you can see here, in the wordpress codex, the function does exactly what its name states: lists the categories, according to the parameters: http://codex.wordpress.org/Template_Tags/wp_list_categories

    If you want that, i'd create my own function and declare some relations between your categories and your created pages (by ID please not slug) (use get_permalink(), it is very useful) then output the categories by your chosing.

    Idea of Associative array between the categories and pages

    $preset_pages = Array(
     [55] = > [2559]
    );
    

    Meaning the category with the ID of 55 would be overwritten by the page with the id 2559.

    You have to do your own query with the IDs however, i'm afraid i can think of no other solution.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 Vue3 大型图片数据拖动排序
  • ¥15 划分vlan后不通了
  • ¥15 GDI处理通道视频时总是带有白色锯齿
  • ¥20 用雷电模拟器安装百达屋apk一直闪退
  • ¥15 算能科技20240506咨询(拒绝大模型回答)
  • ¥15 自适应 AR 模型 参数估计Matlab程序
  • ¥100 角动量包络面如何用MATLAB绘制
  • ¥15 merge函数占用内存过大
  • ¥15 使用EMD去噪处理RML2016数据集时候的原理
  • ¥15 神经网络预测均方误差很小 但是图像上看着差别太大