Thesis Tutorial: 7 Quick Customizations to the Home Page Loop

Lets face it sometimes you don’t want all of our posts to show on the homepage. For instance take this site’s home page, we only wanted to show our most recent post . While you can edit this from within the settings -> reading tab, this will also limit your archive pages. While this works it really isn’t useful to have a paginated archive page is it?

1-post-home-page

Though you would think Thesis would have the option to customize homepage posts built in but in it doesn’t (in v. 1.51). So lets make Thesis work for us.

Using Thesis Hooks

If you have worked with the Thesis WordPress Theme in the past you understand how easy it is to customize it via hooks, if you haven’t we recommend you take a second to read over Thesis Hooks for Dummies.

Sugarrae does a great job “dumbing down” the thesis hooks mumbo jumbo that you will find within the user guide. Hooks are really easy to work with once you get the hang of them. In fact we find they to be easier to use than editing theme files.

Elegant Solution

So know that you know the basics of Thesis Hooks lets elegantly build a solution that allows us tocustomize the loop for the home page. To do this we will be using the built in WordPress function “query_posts.”

7 Quick Customizations to the Home Page Loop

As you may already see there are numerous reasons why you may want to limit the posts on your home page but the following examples will cover how to:

Finding Your Category ID

Find-Wordpress-Categories

Many of the examples below deal with categories, before we get started lets go over how to find your category id. They can be found under Posts -> Categories by hovering over the link on the right side and looking in your status bar for the “cat_ID” url parameter. If in question look at the photo above.

Limit the Number Posts within Home Page Loop – Return to Top

First Lets start with the simple example of limiting the number of posts shown on the front page.

In the example below you can change the number of posts to whatever suits your best. Use “showposts=-1” to display all of your posts.

It has come to my attention that the previous/next links where not working on our home page. To remove this navigation simply add remove_action('thesis_hook_after_content', 'thesis_post_navigation');. I know it isn’t the cleanest solution but these links were leaking link juice anyways. :)

function limit_front_page() {
	global $query_string;
    if (is_home()) {
        query_posts($query_string.'showposts=1'); //Number of posts you want to show.
    }
}
add_action('thesis_hook_before_content', 'limit_front_page');

Offset Posts to Account for Featured Content – Return to Top

Lots of thesis users have tried to implement a featured content slider on their site. This is great but who wants to see duplicate posts. Fix this issue by offsetting the number of posts.

function limit_front_page() {
	global $query_string;
    if (is_home()) {
        query_posts($query_string.'showposts=10&offset=4');
    }
}
add_action('thesis_hook_before_content', 'limit_front_page');

Show Only Posts from a Specific Category or Categories – Return to Top

Depending on how you want your site laid out you may only want to show posts from a specific category or categories. For example you only want to show posts from your “WordPress” and “Thesis” categories you just need to exclude their category id’s. In this example the ids are 2 and 6 respectively.

function limit_front_page() {
	global $query_string;
    if (is_home()) {
        query_posts($query_string.'cat=2,6');
    }
}
add_action('thesis_hook_before_content', 'limit_front_page');

Exclude Posts from a Single Category – Return to Top

Now what about if you have a category you just don’t want to show on the home page. Why not exclude that category?

Lets say that we have a category that holds all of our “Personal Posts” and we don’t want that displayed on the homepage. We should just exclude that category from being shown, in the example below swap out the category ID for your specific category.

function limit_front_page() {
	global $query_string;
    if (is_home()) {
        query_posts($query_string.'cat=-3');
    }
}
add_action('thesis_hook_before_content', 'limit_front_page');

Show Posts from a Specific Tag – Return to Top

We’ve gone over a ton of examples on how to work with categories, what about tags?

In this example lets say that we only wanted to display posts on our home page are tagged either “thesis” or “wordpress”. We would use the following code.

function limit_front_page() {
	global $query_string;
    if (is_home()) {
        query_posts($query_string.'tag=thesis,wordpress');
    }
}
add_action('thesis_hook_before_content', 'limit_front_page');

Show Posts from a Specific Author – Return to Top

If you have a multi author blog you may want to show posts the posts from the admin you would use the following code.

function limit_front_page() {
	global $query_string;
    if (is_home()) {
        query_posts($query_string.'author_name=admin');
    }
}
add_action('thesis_hook_before_content', 'limit_front_page');

Show Posts from a Custom Field – Return to Top

The ability to limit posts to a custom field will be specially useful if you were going to build a custom content slider. In this example we want to limit the homepage to displaying only posts that have a “featured_image” custom field defined.

function limit_front_page() {
	global $query_string;
    if (is_home()) {
        query_posts($query_string.'meta_key=featured_image');
    }
}
add_action('thesis_hook_before_content', 'limit_front_page');

While there are 1000s of potential combinations of how you can customize your home page content, this is just a quick overview. If you are a true ninja check out the wordpress query_posts page and find out all the options you have at your finger tips. Now go out and customize! We Look forward to seeing what your creative minds come up with!

Nick Reese is a multi-passionate entrepreneur who believes anyone can transform their business and life they they’ve got guts and hustle. He’s also the co-founder of Broadband Now which aims to simplify the broadband shopping process.

Written by

Nick Reese is a multi-passionate entrepreneur who believes anyone can transform their business and life they they've got guts and hustle. He's also the co-founder of Broadband Now which aims to simplify the broadband shopping process.

«
»

Comments are closed.