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!

Sign Up Now for Free Updates and Exclusive Content:

Learn how to write killer content, get more traffic, make money, and more by entering your email below:

Written by Nick Reese

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

  • dj says:

    Thanks for this. I’ve got a featured post box and i’m trying to not duplicate the posts on the rest of the page. Is there a way to to basically say – ‘if these posts exist in the feature box’ then don’t show them on the page? my feature box isn’t for the latest posts necessarily. I tag them as a category called ‘featured’.

  • Wordpress and Thesis: perfect match « Theolternative says:

    […] look the way you like. By means of hooks, you can customize behaviour and layout of your pages. See this post for further explanations. In a short time I was able to achieve this result. I’m very happy […]

  • Taz says:

    Thank you for your help. Using Thesis theme, I just want to show one particular post as I am creating a consultancy website. That post will remain on the home page even if I continue creating other posts.

    Any specific code, sorry if you have already dealt with it and I haven’t noticed!

  • Sonya says:

    Hi Nick,

    Could you tell me how I could add more then one article to the feature box and have them changing at intervals? Is it also possible to have a navigation bar underneath the feature box………… so you can click through each article separate. Would there be something else that I would use to do this other then the feature box?

    Cheers

    Sonya

  • Sonya says:

    Hi Nick,
    Thanks for that. One more thing if thats ok….. I put this code you gave us

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

    How do I tell it what posts to not to show on home page. At them moment with this code it shows none except for my feature box.

    Cheers

    Sonya

  • Hi and thanks for those great tips.

    I used the “Exclude Posts from a Single Category” code to exclude my featured posts from being displayed on the frontpage, as I use the feature box to display those instead.

    This is my code:

    // Avoid FEATURED posts to be shown on frontpage
    function limit_front_page() {
    global $query_string;
    if (is_home()) {
    query_posts(‘cat=-447′);
    }
    }
    add_action(‘thesis_hook_before_content’, ‘limit_front_page’);

    Now the only problem is, when somebody use the “previous entries”-link at the bottom of my frontpage, so that the URL changes into /page/2 and /page/3 etc., the newest posts are still being displayed. If I disable the above code, then it works like it should.

    I assume it’s because the code above ignores the /page/ thing from URL and just displays the newests posts excluding category “447”.

    Do you have a suggestion for this?

    Thanks.

    • Ryan P says:

      I’m having the same problem as Klaus. Does anyone have modifications to the limit code that could help?

      • Danny Ashton says:

        Hi I am also having a problem.

        When i follow your advice:

        It hass come to my attention that the previous/next links where not working on our home page. To remove this navegation 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. :)

        This removes the link from all category pages of my site. Whilst i agree that it’s nice to remove the link from the homepage i don’t think its worth reducing the amuount of pages that google can access via my category pages.

        Is there a way to just remove the link from the homepage and not the category pages?

        Thanks
        Danny

  • John says:

    Hi Nick,

    Stumbling around and limiting home page posts to those in a single category using your suggestion.

    However, when I do it, I’m losing my teaser/excerpt. Any thoughts?

    John

  • Greg says:

    Brilliant. Bookmarked.

  • Hi I would like to know how you made this trick. When I click on the links you provided the browser goes to the place but its going live, or we can see the page scrolling. Have you done in CSS of JS. Can I know what should I know to make this stuff.

    • admin says:

      Senthil,

      I use some JS. You will need Jquery to us this function.

      
      
      
  • fester says:

    Thanks for this clear and concise article. I was able to filter categories out of my home page using the hook you describe, but now only the titles from the posts appear on my home page . Do I have to do something else (change a thesis setting, add another hook) to have the whole post (images & all) show on the home page ?

    Thanks again!

  • Berchman says:

    Wow. How did I not see this tutorial before. Great content here.
    Thanks!

  • kristarella says:

    Good tips, but just so that you know, you only have to use global $query_string; if you’re going to use it in the query, e.g., query_posts($query_string . '&cat=-21');. What that does is take all the parameters that were in the query and then changes only the only that you want to change (i.e., excluding category 21 in the example). This can avoid things like destroying pagination.

    global doesn’t do anything in itself, it just makes a variable that is specified elsewhere available for use within your function.

    Don’t want to come across as a know-it-all, I think this is an excellent blog, but if we don’t help each other out we won’t learn as efficiently as we could. ;-)

    • Kate says:

      Hi Nick & Kristerella,

      Love the tute, exactly what I was looking for, but as Kristerella said it breaks my pagination (ie you get the same 8 posts on page 2/3/4 etc..)

      Not sure exactly what she was saying the fix was though, help!

      Here is what i have added so far.

      function limit_front_page() {
      global $query_string;
      if (is_home()) {
      query_posts(‘cat=2393′);
      }
      }
      add_action(‘thesis_hook_before_content’, ‘limit_front_page’);

      thanks so much!

      • kristarella says:

        You need to change your code to:

        function limit_front_page() {
          global $query_string;
          if (is_home())
            query_posts($query_string.'cat=2393');
        }
        add_action('thesis_hook_before_content', 'limit_front_page');
  • Romulo says:

    Hey dude sorry for asking this after so many time of the post, but I’m having serious problems in my Home page. The thing is I’m using the Home as a static page, and my posts go to my Blog page. But I need to show the latest post from a category on the Home page. When I insert the code provided for “Show Only Posts from a Specific Category or Categories” my Home page is not affected. Instead, the Blog page is. And the code works like a charm there. But I need this Blog page to show ALL of my posts, while the Home page is to show only the latest of an especific category.
    I’ve already searched for a solution for this on Google, forums, etc. and can’t seem to find a working code to setup it the way I need. Hope you can help me.
    Great blog you have there. It helped me a lot in the past. Thanks in advice!

  • Romulo says:

    Thank you so much, dude! It solved my main problem, I think now is just about customization. My Home page now shows the only post I need (the site will be updated daily with a video and a short description of it), but I need it to show the entire post – including the video – or at least until a “read more” link.
    Any ideas?
    One other thing is a text showing up on the post, like:
    From the category archives: Vitrine Diária (wich is btw the category I want to show). How can I remove it?
    Well, my site is still under development, but you can check it out here: http://www.suavitrine.com/
    One more time, thanks a lot. A LOT. ;)

    • Nick Reese says:

      Try checking out your thesis options to show entire posts or full entries.

      If i can remember correctly try toggling the one on archives.

      • sandra says:

        I’m also trying to remove ‘from the category archives’ and haven’t had any success. Under thesis options I have entire posts selected, but not sure what I should do on archives….please explain.

        • breslinv says:

          Add the following to your custom functions file

          // remove “From the category archives’
          remove_action(‘thesis_hook_archive_info’, ‘thesis_default_archive_info’);

  • Romulo says:

    Holy crap! It worked like a charm. Thank you SO much! :D
    Now I got to find out how to display that video, but I already have what I wanted more. The video thing I think has something to do with it being on the archives, it will only show when you click the post itself.
    Thank you so much. Keep rockin’ dude!

  • juan says:

    hi nick i want to put on my homepage 15 post but thesis is limited to 10 how i can change this and,whrer to put the code, thanks i use thesis 1.7

    • Nick Reese says:

      Juan, it would be easier for you to change your post count in your wordpress settings.

      I think it is under reading. Total posts should be 15. It defaults to 10.

  • Carlo says:

    Hi,

    I have a similar set up to Romulo above – static homepage and blog page elsewhere…however I want the latest 3 posts to show on the homepage. I used the code and swapped is_home to is_front_page as you suggested, but it wipes out the static content I built into the “home” page and only shows the latest 3 posts.

    I would like to have all my static content (combination of text and images) showing at the top of the content box, then underneath that I want the latest three posts.

    How would I do that? Thanks!

    • Nick Reese says:

      Carol,

      You’d need to setup a custom loop and hook it where you want it to be used.

      http://codex.wordpress.org/The_Loop#Multiple_Loops_in_Action

      • Carlo says:

        Thanks Nick. I just read through that. Their use is a little different than what I want to do, but I know I can customize it. I just don’t know how to, I know virtually nothing about PHP (although I have done some C programming many many years ago).

        First of all, how do I customize that code to only show the latest THREE posts? That code looks like it will keep posting as long as there are posts. Also, I want them to just be the excerpts (including the thumbnails). And would I just stick the code inside a function and assign it to a hook?

        I realize I may be asking for too much, but worth a shot ;)

  • Tom says:

    Hi All,
    just wondering when hooking in to the posts like Nick has outlined above, is there a way to change the layout/template of the post and also include post images etc
    Cheers,
    Tom

  • Kristin Antin says:

    This is SO helpful! Exactly what I’ve been looking for!

  • “It hass come to my attention that the previous/next links where not working on our home page. To remove this navegation 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. :)”

    Any solution to allow the pagination to still work with limited home posts? I have removed the hook in question to add a numbered page button. method.

    Thanks, great tutorial overall.

  • tangologix says:

    thank man for such a nice piece of info , i am using thesis them on my site, i need some help here i can see you have put under neath your header digg it, stumble, reddit , tweet button how can i do this with thesis? what is hook code that i have to paste in header or under neath header? thanks for help will be back to see if any one replies thanks in advance.

  • Andrea says:

    So, I figured the same logic for excluding a category would work with ‘tag’ but when I did that, it excluded all tags rather than single one I identified { ‘tag=3 }. Is there something different the code needs to say to exclude tags from the page?

    Thanks!

  • The Huge Thesis Compilation| Skins , Resources , Tutorials says:

    […] Thesis Tutorial: 7 Quick Customizations to the Home Page Loop […]

  • Dee says:

    (hope you’re still answering questions about this)

    I used the code below for showing just certain categories on the front. It works just fine. However, it disabled my slider which runs on a jquery library script that’s placed in the head via Thesis Design/Home page options. The slider doesn’t slide anymore, and all the pictures I had in the slider are now on the front page. I have no clue why. Do you? Thanks!

    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’);

  • Sylvia says:

    Thanks for the code! I used the function to limit the number of posts on my blog front page on my own site and it worked flawlessly….but now using the same chunk of code on another website, it removes ALL posts from the loop and the page is blank. Any ideas about what could be causing that problem? I’m using the EXACT same chunk of code on both sites and hooking it into the same hook…

  • Mike Morrow says:

    Nick,

    I have added the “Show Only Posts from a Specific Category or Categories” function to my custom functions file but it’s not working. I’ve tried it with various category id’s and in different locations in the custom functions file, but ALL of my posts are still showing up. Is there a certain code string for hooks that need to go before or after this code that I’m missing. I copied and pasted the code in and changed the category id?

    Help!!!

  • Mark says:

    is there a way to display 1 post (most recent) per category? So basically I have 5 categories. I need 1 post from each to display on the home page. Thanks

  • Hi. I need to exclude a category from my home page une the loop. Can i do this in my index.php file :

    $lastposts = get_posts(‘showposts=8&cat=-cat_name’);

    Tank you for your help.

  • 6 Great Thesis Tutorials for Noobs says:

    […] Thesis Tutorial: 7 Quick Customizations to the Home Page Loop […]

  • Kat says:

    Very useful. Thanks!

  • bindin says:

    Thank you dear. Its pretty helpful for me.

  • Nick Tzu says:

    DJ basically what I did to make this same thing work was set up two queries. The first query finds all posts tagged with featured and limits them to 4. The next bit of code modifies Thesis’s loop to exclude the featured category. My featured category id is 21.

    Code block 1
    Here is the first block of code. This works just like the standard loop.

    < ? function thesis_featured_slider(){
    global $post;
    global $more;
    if(is_home()){
    $my_custom_query = new WP_Query('cat=21&showposts=4');
    while ($my_custom_query->have_posts()) : $my_custom_query->the_post();
    
    //Do your stuff like echo out the title or content.
    
    endwhile; ?>
    
    < ? }
    }
    add_action('thesis_hook_before_content','thesis_featured_slider');?>
    
    

    Code Block 2
    Here is the 2nd block of code. This excludes the featured category.

    < ? function limit_front_page() {
    	global $query_string;
        if (is_home()) {
            query_posts('cat=-21');
        }
    }
    add_action('thesis_hook_before_content', 'limit_front_page'); ?>
    

    Hope this helps. It works for me on another blog I run. I’d love to hear if it works for you.

  • Nick Tzu says:

    Taz, I’d suggest you try using the static home page tutorial. Joe does a great job walking you quickly through the process.

    http://joekraynak.com/blog/computers/creating-a-static-home-page-with-thesis-and-wordpress.html

  • Taz says:

    Thank you Nick. I am on my way to check it out. Hope it will work out for me. Great blog you got here bro!

  • Kelly says:

    This is helpful but I am still having problems because I want to show my featured category in the teasers below my featured box. I only want to omit the featured items that are shown in the feature box (remove the duplicates from the teasers on the front page, not the whole category).

    Any idea how I would do the conditional for that?

  • Nick Tzu says:

    Sonya,

    Right now the feature box has very little functionality. You pretty much have to make your own solution. I have created something and plan on releasing it at some point. Just not happy with how it works right now.

    If you are looking for a quick solution check out the post @graywolf did on how to integrate a plugin.
    http://www.wolf-howl.com/blogging/visual-slider-thesis/

    I think this will do what you need it to. If you also have questions ping the #thesiswp channel on twitter. There are a ton of very helpful people (including myself) there.

  • Nick Tzu says:

    For my blog I ran into the same issue. I simply queried all the posts in a new custom query. Then checked to see if they had a custom field filled out. If it did I would add the post ID to an array and echo out the need info for the featured post.

    Once I had looped through my featured posts, I then used a similar function to the one above to exclude the posts that I had already displayed by referencing the array.

    I’m on the road and don’t have access to the full code, but if you are familiar with WordPress and Thesis, you might be able to hack it.