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
coffee latte near white wireless keyboard and Apple EarPods on the table photography

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?

Neuroscientist reveals a new way to manifest more financial abundance

Breakthrough Columbia study confirms the brain region is 250 million years old, the size of a walnut and accessible inside your brain right now.

Learn More

Picture of Nathan Rice

Nathan Rice

Nathan is a blogger and freelance web designer, specializing in WordPress theme development. He runs his own blog at NathanRice.net ranging in topics from web design, to WordPress tips, and is a contributer at Performancing, The Blog Herald, and WordPressThemes.com.

RECENT ARTICLES

TRENDING AROUND THE WEB

7 things you don’t realize you’re doing because you were raised by strict parents

7 things you don’t realize you’re doing because you were raised by strict parents

Global English Editing

4 zodiac signs who rarely ask for help, even when they need it

4 zodiac signs who rarely ask for help, even when they need it

Parent From Heart

7 signs someone is emotionally detaching themselves from you, according to psychology

7 signs someone is emotionally detaching themselves from you, according to psychology

Global English Editing

7 societal expectations to ditch for a happier retirement

7 societal expectations to ditch for a happier retirement

Hack Spirit

If you want your 70s to be the greatest years of your life, say goodbye to these habits

If you want your 70s to be the greatest years of your life, say goodbye to these habits

Global English Editing

6 zodiac signs that naturally stay fit as they age

6 zodiac signs that naturally stay fit as they age

Parent From Heart