Home page needs different # of posts than category page (7 posts)

  1. Matt
    Posted 7 years ago #

    Clicking on domain.com/category/category-name I'd like to show 100 posts. This uses my theme's index.php template.

    Clicking on the site's index page I'd like to show 8 posts. This uses my theme's home.php template.

    Problem is they both display whatever I define in Settings->Reading->Blog pages show at most

    What can I do to free one of these from this setting?

  2. Matt
    Posted 7 years ago #

    Rephrase: how do I make a "manual" loop, one that isn't subject to the "show # posts" setting?

  3. Matt
    Posted 7 years ago #

    Nobody has this requirement but me?

  4. Put this <?php query_posts('showposts=10'); ?>

    Before this: <?php while (have_posts()) : the_post(); ?>

    Change '10' to however many you want to show. Party on, Garth.

  5. SimonJ
    Posted 7 years ago #

    Yes, you can modify the loop in home.php to show a specific number of post :

    You should have something like this in your home.php :

    <?php if (have_posts()) : ?>
    <?php while (have_posts()) : the_post(); ?>

    Change it for :

    $posts = query_posts($query_string .
    if (have_posts()) : while (have_posts()) : the_post(); ?>

    Here, we show 8 posts... Note the : &showposts=8. You can set it to anything you like.

    Now, your home.php uses this modified loop, and your index.php still use the default one to display the categories...

    Also, read this codex page :


  6. Matt
    Posted 7 years ago #

    Thanks Simon and Ipstenu.

    Ipstenu, <?php query_posts('showposts=10'); ?> blew up my category filter, so that each category page showed every post.

  7. kangel
    Posted 6 years ago #

    Is anyone having issues with the code posted by Simon in wp 2.8.4? This code was working great until I updated (I think that's when it broke...) I now get an error page.

Topic Closed

This topic has been closed to new replies.

About this Topic