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 拟通过pc下指令到安卓系统,如果追求响应速度,尽可能无延迟,是不是用安卓模拟器会优于实体的安卓手机?如果是,可以快多少毫秒?
  • ¥20 神经网络Sequential name=sequential, built=False
  • ¥16 Qphython 用xlrd读取excel报错
  • ¥15 单片机学习顺序问题!!
  • ¥15 ikuai客户端多拨vpn,重启总是有个别重拨不上
  • ¥20 关于#anlogic#sdram#的问题,如何解决?(关键词-performance)
  • ¥15 相敏解调 matlab
  • ¥15 求lingo代码和思路
  • ¥15 公交车和无人机协同运输
  • ¥15 stm32代码移植没反应