• dtrickky

    (@dtrickky)


    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

  • The topic ‘WP Category Query’ is closed to new replies.