Filtering latest posts by category
-
I have searched “filter latest posts by category” and don’t seem to be finding what I’m looking for.
Here’s what I want to do:
1. Grab the latest posts regardless of category
2. Show the most recent post published.
3. Show the next most recent post that has a different category
4. Repeat third item one more time. (3 posts with different categories)
5.I want the loop to be category agnostic: The author can make as many different categories as they want and as long as they meet the requirement of being a)the most recent post or b) the most recent post but a different category, it will show as one of the three posts displayed.Using stuffannforgottotellyou.com posts as an example,
“Template files for wordpress themes” would show first, “A great fall day” would show second, “Makani” would be the third post in this monster I’m trying to create.Here is my loop so far:
<?php query_posts('orderby=category&posts_per_page=3'); ?><!-- grab posts, order by category and only show three posts--> <!-- starting loop--> <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?> <div class="post"> <!-- Display the Title as a link to the Post's permalink. --> <h2><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2> <!--show off category--> <p class="postmetadata"><?php the_category(', '); ?></p> </div> <!--ending loop--> <?php endwhile; else: ?> <p>Sorry, no posts matched your criteria.</p> <?php endif; ?>
Basically, it’s showing Title and category. It’s listing posts, most recent first (so far so good) but not showing 1 per category. Would anyone like to take my n00b hand and help me out? What dumb thing have I forgotten?
- The topic ‘Filtering latest posts by category’ is closed to new replies.