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...

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


It will give you the same structure as shown above:

wp_list_categories(array('hide_empty'=>0, 'hierarchical' => true, 'include' => array('12','12')));
        // 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>';
        // join and output links with separator
        echo join($links );

This is the answer i am looking for thanks for replys

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.