WordPress.org

Ready to get started?Download WordPress

Forums

List of categories with post titles (3 posts)

  1. Nicholas
    Member
    Posted 2 years ago #

    Hi,

    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:
    http://www.transformationpowertools.com/wordpress/hierarchical-category-list-with-post-titles

    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. alchymyth
    The Sweeper & Moderator
    Posted 2 years ago #

    instead:

    // 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 );
     }
     endforeach;

    try:

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

    (untested)

  3. Nicholas
    Member
    Posted 2 years ago #

    Hi alchymyth,

    That worked perfectly! Thank you very much!

Topic Closed

This topic has been closed to new replies.

About this Topic