I have the following code that lists out the children categories on a separate page when you click on its parent category. The code renders a list like so:
Home › Archive for IQ Issue 7
However I would like to retrieve the latest post from each of these categories and print underneath the category name. How could I achieve this within the loop below? I have tried several foreach loops but none seem to print the correct info. Thanks in advance.
<?php $this_category = get_queried_object(); // if parent is 0, category is top level if( 0 == $this_category->parent ) : // top level category, // show child categories of this issue $args = array( 'child_of' => $this_category->term_id, 'title_li' => '', 'hide_empty' => 0 ); ?> <!-- output a list of child cats for this issue see also get_categories or get_terms if you wish to use your own markup--> <?php wp_list_categories($args); ?> <?php else : // child category, // show articles in this subcategory, etc. echo 'child category'; endif; ?>