admin管理员组

文章数量:1122832

I am building a quotes website and i have 2 main categories like Topic & Authors
Every quote will have Author name and topic name and those are sub categories of Topic & Author.
AND my question is
i want to display only Author categories that is a sub category of a Authors category please help me...

Topic
- Love
- Life
- Friends etc
Authors
- Author1
- Author2
- Author3

I am building a quotes website and i have 2 main categories like Topic & Authors
Every quote will have Author name and topic name and those are sub categories of Topic & Author.
AND my question is
i want to display only Author categories that is a sub category of a Authors category please help me...

Topic
- Love
- Life
- Friends etc
Authors
- Author1
- Author2
- Author3

Share Improve this question edited Jan 25, 2017 at 14:57 fuxia 107k38 gold badges255 silver badges459 bronze badges asked Jan 25, 2017 at 11:52 pandupandu 1
Add a comment  | 

2 Answers 2

Reset to default 0

It will give you the same structure as shown above:

wp_list_categories(array('hide_empty'=>0, 'hierarchical' => true, 'include' => array('12','12')));
    <?php
        // names / IDs of parents
        $parents = array(
            'par2' => 76
        );
        // get post categories
        $categories = get_the_terms( $post->ID, 'category' );
        // output top level cats and their children
        foreach( $parents as $parent_name => $parent_id ):
        // output parent name and link
        //echo '<a href="' . get_term_link( $parent_id, 'category' ) . '">' . $parent_name . '</a>: ';
        // initialize array to hold child links
        $links = array();
        foreach( $categories as $category ):
        if( $parent_id == $category->parent ):
        // put link in array
        $links[] = '<li><a href="' . get_term_link( $category ) . '">' . $category->name . '</a></li>';
        endif;
        endforeach;
        // join and output links with separator
        echo join($links );
        endforeach;            
    ?>

This is the answer i am looking for thanks for replys

本文标签: List only child categories a post is inof a specific parent category in wordpress