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:

< ?php $my_query = new WP_Query('showposts=1');
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_title() ?>
< ?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:

< ?php query_posts('showposts=5'); ?>

Then, where you would normally call the [standard] Loop, alter it like so:

< ?php if (have_posts()) : while (have_posts()) : the_post();
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 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′);
    foreach($myposts as $post) : setup_postdata($post); ?>

  • < ?php the_title(); ?>
  • < ?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).


  1. Armen

    Nice work Charity. I’ll take an even closer look at this some time when it’s not so late. However, for now…Stumbled!


  2. Charity

    Thanks 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…


  3. Ryan Imel

    Thanks for this post, Charity. I’ll be linking over to you from Theme Playground :).


  4. Theme Playground | Design Adaptations on Non-duplicating Feature Entries

    [...] 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 [...]


  5. Benjamin Sterling

    Very nice post, and I second Charity, really nice looking blog.

Other Recent Articles

In Reviews »

Clever Development With Coda

07/15/08
If you follow design related blogs, it seems you can't click a mouse anymore without Coda's icon making an appearance. I heard about this software long before buying my Mac, but because it's exclusive to that platform, I was never able to give it a test run. Now eight ... [ » ]

In Inspiration »

Have You Ever?

06/25/08
If you know me very well, you know how important music is in my life. It's playing at all times in my house, and I embrace all kinds of genres. I don't talk about it much on this blog, but I should. Music and creativity, in my opinion, are inextricably ... [ » ]

In Design »

The Evolution of a Logo (I Can Live With)

06/19/08
One of the most frustrating things for me since I started writing on this blog was the lack of a logo I really loved. That's not to say I haven't tried. But logo design, to me, is kind of a thing all it's own and I'm just not very good ... [ » ]