Now Reading
Don’t Show Me the Same List Twice

Don’t Show Me the Same List Twice

If you’re like the thousands of other bloggers out there, when you first started your blog, you went to the theme viewer or did a google search for free WordPress themes and found yourself something that you liked. Personally, I’m not a fan of themes that display the seemingly endless list of full articles right there on the homepage. I’d much rather see a couple of feature stories, and a list of either older stories, or a list of categories that I can browse through. But alas, even the free themes I’ve released have had the endless, reverse-chronological list of stories with full text and a “previous – next” link at the bottom.

And this is the case for most of the free themes out there.

What’s even funnier is the fact that some bloggers/theme designers put a list in a sidebar called “recent stories/articles”.

What?! You mean that not only do I get the long list of stories on the homepage, but I’m also getting another list in the sidebar with the exact same list? Seems like a waste of real estate, huh?

But it doesn’t have to be. By implementing this simple trick, you can change the sidebar information to display only a list of stories that are older than the stories on the homepage. Here’s how…

The Prep

First thing to do is figure out how many stories are being displayed on your homepage. Go to the WordPress dashboard and click on Options – Writing and find the section that says “Blog Pages” and check to see the number in the box that says “Show at most X posts”.

The Code

Now, find the section in your sidebar.php file that displays the recent articles. The template tag will look something like this:

<?php get_posts(‘numberposts=10’); ?>

This will output a list of your most recent 10 posts. In order to change this list to the most recent posts NOT on the homepage, we will need to offset this list. Remember the number of stories set to display on your homepage? Let’s say that number is 15. All you need to do is add the “offset” qualifier inside the parenthesis to get the list offset. It should look like this now:

<?php get_posts(‘numberposts=10&offset=15’); ?>

See Also
lower third tv

But what about when we leave the homepage?

Good question. If we’re not on the homepage, there’s no reason to offset the list. In fact, if someone comes to your site from an incoming link or google search, you WANT them to be exposed to your most recent posts. So, what we’ll do is use the is_home() conditional tag to only offset when we’re on the homepage. Everybody has their own opinion how how to write php conditions, but here’s what I would do:

<?php
if (is_home()) {
get_posts(‘numberposts=10&offset=15’);
}
else {
get_posts(‘numberposts=10’);
}
?>

Now, every time you’re on the homepage, your list is offset, and if you’re on any other page, the list displays the latest stories from your blog, not offset.

Simple huh?

View Comments (7)
  • As I implemented on my blog I had problems with it because of the apostrophes you use. They are not only different, but also seems to get in the way of it working. After having replaced them with plain ‘ it worked.

    The one I used make use of slightly other commands, but luckily this “home” or “not home” tip could be integrated when I changed the commands as well. Thanks for the tip!

  • Sorry Jan,
    WordPress likes to change the quotes to the curly ones when you publish. Like you did, just replace them with regular old quotes. Glad you figured it out.

    Nathan

  • I like this solution and the fact you account for the Home page condition. However, I am using widgets, so the get_posts code isn’t in my sidebar.php (actually obar.php in my theme which has two sidebars). get_posts isn’t in the widgets.php file in the plugins folder either. I’m thinking I should revert to hand-coding the sidebars instead of using widgets to accomplish what I want. . . Or is there something else I can do?
    Many thanks for your solution, and any help in applying it when the widgets plugin is being used.

  • I tried the code but it didn’t work. It sometimes needs a variable assigning to get_posts so this is what worked for me.

    “>

    NOTE:

    I used $gposts as a variable instead of $posts for the following reason given by the WordPress Wiki for get_posts.

    Quote:

    Assigning get_posts() to the variable $posts, when you may already have it in use for The Loop, can lead to conflicts. If so, create a variable of your own (i.e. $gposts, $my_posts).

Scroll To Top