How to Set Up Non-duplicating Recent Entries
Nov 2nd, 07 | Comments are closed.It’s common knowledge by now that a Recent Posts list on the home page of a blog is beneficial for garnering more page views, just as a Related Posts list is for single entry pages. Unfortunately, many of the blogs I’ve seen using this technique are duplicating their most recent entry. Duplicate content is always a concern for blogs, and particularly those powered by Wordpress. Fortunately, there’s a fix for it - at least when it comes to recent posts. Here’s how…
Instead of starting with the standard Loop, we’re going to open a query, like this:
while ($my_query->have_posts()) : $my_query->the_post(); $do_not_duplicate = $post->ID; ?>
This tells Wordpress you only want one entry (the most recent) returned by the query, that there’s more to come, and don’t repeat it. Savvy? ;) Note: this will override any settings you have in the Dashboard for how many posts to display on your home page.
Now you should see some recognizable code calling the post title, meta data, and content, or some variation of these functions:
< ?php the_time('n/j/y') ?>
< ?php the_content(); ?>
Beyond this you may have a call to your sidebar, some ads, or whatever you’ve dropped in. Just be sure to close your query with an endwhile statement (not endif).
Moving down the page to your Recent Entries section, you’ll need to alter the code a bit more. Again we start with a query, this time with however many posts you want displayed:
Then, where you would normally call the [standard] Loop, alter it like so:
if( $post->ID == $do_not_duplicate ) continue; update_post_caches($posts); ?>
Depending on how you want your list to appear, you may want to include the title and excerpt, the title and post meta, or all three, but it’s basically going to look like this:
-
< ?php the_title() ?>
< ?php the_time(’n/j/y’) ?>
< ?php the_excerpt(); ?>
< ?php endwhile; ?>
Whatever additional content you might have.
< ?php else : ?>
Not Found
Bla bla blah
< ?php endif; ?>
You just created a custom index page which will show your most recent entry in full, along with a list of 5 previously featured entries - all without penalty of duplication. Of course, there’s more than one way to do just about everything in Wordpress. This is the only way I know of, but if there’s a better way I’d love to hear it!
Update: Suppose you want to do add a list to your single.php page as well? This can be done with a little less code, using another [foreach] loop:
Recently Featured
- < ?php global $post; $myposts = get_posts(’numberposts=5&offset=1′);
- < ?php the_title(); ?>
foreach($myposts as $post) : setup_postdata($post); ?>
< ?php endforeach; ?>
This tells Wordpress to display the titles of the most recent 5 entries, prior to the very latest one (which of course will already be displaying in full in the main content section).

Nice work Charity. I’ll take an even closer look at this some time when it’s not so late. However, for now…Stumbled!
Nov 2, 07 | 10:39 amThanks Armen. :) By the way, I love the look of your blog! Nice clean layout, very warm. Good work on your designer resource list as well. I’ve also been putting together a list because - like you said - my bookmarks are overwhelming at this point. :) One of these days I’ll get it published…
Nov 2, 07 | 10:56 amThanks for this post, Charity. I’ll be linking over to you from Theme Playground :).
Nov 3, 07 | 1:03 pm[...] great little tutorial went up recently by Charity at Design Adaptations, all about how to feature a post without it repeating in your main entries list. Great stuff. I also believe Charity’s new design may be up for review [...]
Nov 6, 07 | 10:26 amVery nice post, and I second Charity, really nice looking blog.
Nov 6, 07 | 4:12 pm