Show one post by category on the index page
-
Hello,
I will try to explain this as clearly as possible… Any help would be muchly appreciated =)
I have four main categories in my site:
1 – Updates
2 – Tutorials
3 – Graphics
4 – StockI wanted my index page to show the latest post from each category, like this:
Latest Update Title
ExcerptLatest Tutorial
Title
ExcerptLatest Graphic
Image
NameLatest Stock
Image
NameIn order to do this, I have inserted four instances of the loop. For example, to show the latest update I have used something like:
<?php while (have_posts()) : the_post(); ?>
<?php if ( in_category(1) ) { ?>
<?php the_excerpt() ?>
<?php } else {
}; ?>
<?php endwhile; ?>Then, I used the code
query_posts($query_string . "showposts=4");
to make it display only 4 entries. Obviously this does not work as intended: if I have two posts from the category ‘Stock’ that have been created after the latest post from the category ‘Updates’, they will both show up. So, the place where the latest update was supposed to be will be left blank.The question is how can I show only the latest post by category, even if one of the categories is updated more frequently? As I am using 4 loops, can I instruct each of them to display only one post?
Thank you so much in advance! ??
- The topic ‘Show one post by category on the index page’ is closed to new replies.