Support » Themes and Templates » posts on the homepage

  • hi,

    can somebody help me how to put a limit on the posts
    that will be on the homepage, like for example only 5 posts.
    so when i make new post it wont keep filing up on the homepage.
    theme is originally not like that i just get the post and side
    bar to appear on the homepage but when i make new post it keeps
    filing up and it become messy.

    i hope someone can help me.

    thank you.

Viewing 1 replies (of 1 total)
  • You want to modify the main page query for that makes “The Loop”. Assuming you only want to affect that one page then query_posts() is how to do it.

    query_posts() modifies the query that has already been created for the current page loop. It is not for creating new loops ONLY modifying the current loop. So…

    For example to limit the number of posts output to 5 on the home page add this to either your index.php or whichever template is displaying your home page.

    query_posts( 'posts_per_page=5' );

    Or you could just add the same thing with a condition to your functions.php file:

    if ( is_front_page() ) {
        query_posts( 'posts_per_page=5' );

    And so you know you could use the same query_posts() function to do other modifications to The Loop such as limit the categories you want to display on the home page loop:

    query_posts( 'cat=4' );
    query_posts( 'category_name=staff' );
    query_posts( 'cat=2,6,17,38' );

    Where the numbers are the id’s of the category to include. There are so many examples on the codex link at the top (I just copied those).

    Find your day well.

Viewing 1 replies (of 1 total)
  • The topic ‘posts on the homepage’ is closed to new replies.