- This topic is empty.
December 11, 2011 at 6:07 pm #35593rifatlasMember
I am migrating a static magazine site to wordpress. I would like to have a front page displaying multiple categories. Each category will display the title, thumbnail, author, date and excerpt of a few posts, e.g “politics” with its three latests posts, “environment” and “health” with their two latests posts and “technology” with its latest post and so on.
On top of that I would like to have a “latest news” category. In this category, the posts will be displayed in the same way as the various categories on the frontpage, i.e with title, excerpt etc. It should also be possible to display child categories e.g (Politics>Asia>)India. Clicking on “India” would take the visitor to the India page located under Politics>Asia.
The problem I encounter is how to avoid having duplicate posts in the “latest news” category on the front page, since those posts also are in another category, e.g in “politics”. A post in the “latest news” category also in “politics” should only show in the “latest news” category on the front page until it drops out of the “latest news” category, then it moves over to show in the “politics” category on the front page. The post thumbnail, title etc should also be displayed on the “politics” page. (There is no need for pagination on the front page or the other pages, since older posts will exit into archive pages when pages fill up)
I realize its easy to display any number of categories using multiple
, but what about the problem of duplicate posts in the “latest news” category?
Lets say I want to display maybe 10 different categories (meaning 10 loops), some of them perhaps child categories and also display the last few excerpts, thumbnails and titles in the “latest news” category. Should I use
to solve this problem? Or
or something else? I don’t want start in the wrong end and realize it’s not possible and I would need to start from the beginning again.
An example of what I am trying to accomplish is this site, a well-known news blog.
There are many tutorials online, but none that I’ve found deals with the issue of having more than two categories/loops and avoiding duplicate posts. There are so many wordpress magazines and newspapers online so I find it strange that there aren’t any tutorials about this. I’ve searched in books as well but without luck.
Very grateful if someone could point me in the right direction!December 11, 2011 at 6:57 pm #92481TheDocMember
That is a tough one.
I would say for simplicity I wouldn’t worry about duplicates – many major newspaper websites have a latest news and then categories on the page that contain the same articles. I don’t think there is anything wrong with that.
I would use query_posts to target the categories for each of your loops and set the amount of posts to show.
Don’t forget to use wp_reset_query after each loop.December 12, 2011 at 5:50 am #92499BrightonmikeMember
while ($my_query->have_posts()) : $my_query->the_post();
$do_not_duplicate = $post->ID; ?>
Should work.January 5, 2012 at 10:07 pm #94088rifatlasMember
Thank you for your suggestions. I found a simple and excellent solution at wprecipes
How to: Use two (or more) loops without duplicate posts
- The forum ‘Back End’ is closed to new topics and replies.