Sub-Category List of Posts
-
I am trying to display a list of all the posts based on their sub-category. I have it partially working, but for the last “foreach” loop it displays the title (link) with post info (content, tags, categories) twice.
I have a category hierarchy of this:
Articles |-> Adults |-> Students |-> Kids
So, when you go to the “Articles” page there is a list like this:
Articles * Adults * Post Title 1 for Adults * Post Title 2 for Adults * Post Title 3 for Adults * Students * Post Title 1 for Students * Post Title 2 for Students * Post Title 3 for Students * Kids * Post Title 1 for Kids * Post Title 2 for Kids * Post Title 3 for Kids
This is the code I am using:
<?php if (is_page( 'articles' )) { $args = array( 'orderby' => 'id', 'parent' => 9, // Articles 'exclude' => 122 // Subcategory Year ); $cats = get_categories( $args ); foreach($cats as $cat) { $args=array( 'orderby' => 'date', 'order' => 'ASC', 'showposts' => -1, 'category__in' => array($cat->term_id), 'caller_get_posts'=>1 ); $posts=query_posts($args); echo '<h2><a href="' . get_category_link( $cat->term_id ) . '" title="' . sprintf( __( "View all posts in %s" ), $cat->name ) . '" ' . '>' . $cat->name.'</a></h2> '; foreach($posts as $post) { if(have_posts()) : while(have_posts()) : the_post(); ?> <a href="<?php the_permalink();?>"><?php the_title(); ?></a><br> <?php endwhile; endif; ?> <?php } // foreach($posts } // foreach ($cats } // close if articles ?>
Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
- The topic ‘Sub-Category List of Posts’ is closed to new replies.