WordPress show posts in subcategory groups
-
I’m trying to list my posts by subcategory groups on each category page.
I’ve added the following code to category.php and it works well. What I need help with is the automatic detection of the child_of ID (shown as 3 at the moment) – which would be the parent category ID.
Can anyone help? Thanks.
<?php $categories = get_the_category(); $categories = get_categories('child_of=3'); foreach ($categories as $category) { echo '<h2>'.$category->name.'</h2>'; foreach (get_posts('cat='.$category->term_id) as $post) { setup_postdata( $post ); echo '<a href="'.get_permalink($post->ID).'">' . get_the_title() . '</a>'; } } ?>
Viewing 1 replies (of 1 total)
Viewing 1 replies (of 1 total)
- The topic ‘WordPress show posts in subcategory groups’ is closed to new replies.