• Hi All,

    I picked this code up from a poster here and like a dummy didn’t save the thread. This code does exactly what I want it to do: display a list of children categories and their respective posts. However, it only shows the most 5 recent posts and I want the code to generate all posts.

    I could map it out manually, but this system needs to be dynamic. Any advice on how I can change this code to display all posts?

    <?php $cat = 'Writing';
                    $catID = get_cat_ID($cat);
                    $subcats = get_categories('child_of=' . $catID);
                        foreach($subcats as $subcat) {
                        echo '<h3>' . $subcat->cat_name . '</h3>';
                        echo '<ul>';
                        $subcat_posts = get_posts('cat=' . $subcat->cat_ID);
                        foreach($subcat_posts as $subcat_post) {
                            $postID = $subcat_post->ID;
                        echo '<li>';
                        echo '<a href="' . get_permalink($postID) . '">';
                        echo get_the_title($postID);
                        echo '</a></li>';
                        }
                        echo '</ul>';
                        } ?>
  • The topic ‘Display all child categories and posts within that category’ is closed to new replies.