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.

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

报告相同问题?