WordPress.org

Ready to get started?Download WordPress

Forums

WP Category Query (1 post)

  1. dtrickky
    Member
    Posted 2 years ago #

    Hi all.

    I have a parent category page with several child-categories.

    When on the parent category page, which runs off a unique template, I'd like to display the latest 5 posts from each of the child categories.

    Is there a way to query posts which are children of a category? There seems to be a query for children of posts/pages, but I can't seem to make the same concept work using categories. The post/page parameter is used in the code I have so far below, although it doesn't work ('post_parent' parameter).

    <?php
    if ( is_category() ) {
      $current_cat = get_query_var('cat');
      wp_list_categories('&title_li=&show_count=1&child_of='.$current_cat);
    }
    ?>
    <?php
    
    // The Query
    query_posts( 'post_parent='.$current_cat );
    
    // The Loop
    while ( have_posts() ) : the_post();
    	echo '<li>';
    	the_title();
    	echo '</li>';
    endwhile;
    
    // Reset Query
    wp_reset_query();
    
    ?>

    Thanks for any help/suggestions

Topic Closed

This topic has been closed to new replies.

About this Topic