List of categories with post titles (3 posts)

  1. Nicholas
    Posted 4 years ago #


    I am trying to determine how to display a list of category titles, with the corresponding child category or post titles below.

    I have got this working from code provided by @alchymyth that I found here:

    My problem is that I want to list the category titles and corresponding post titles for only certain categories. Not all categories.

    You can see a working example here: http://www.fuimano.topleftdesign.com/?page_id=17

    In the sidebar on the right, under Exhibitions, it lists all categories. If you click on the category title it reveals the post titles and sub categories. I only want to list the Exhibitions category here and not all the categories.

    Any ideas on how to achieve this?

  2. Michael
    Forum Moderator
    Posted 4 years ago #


    // http://codex.wordpress.org/Function_Reference/get_categories
     foreach( get_categories('hide_empty=0') as $cat ) :
     if( !$cat->parent ) {
     echo '<ul><li><strong>' . $cat->name . '</strong></li>';
     process_cat_tree( $cat->term_id );


    // http://codex.wordpress.org/Function_Reference/get_term_by
    $cat = get_category(get_term_by('slug','exhibitions','category'));
    echo '<ul><li><strong>' . $cat->name . '</strong></li>';
    process_cat_tree( $cat->term_id );

    replace 'exhibitions' with the category slug of the corresponding category.


  3. Nicholas
    Posted 4 years ago #

    Hi alchymyth,

    That worked perfectly! Thank you very much!

Topic Closed

This topic has been closed to new replies.

About this Topic