• Resolved miromiro

    (@miromiro)


    I was wondering if there was any straightforward way in 2.1 to set a specific number of posts on the homepage (using Reading>options>show at most), but have all of the archived categories appear on a single page.

    I found this advice:
    Limit number of posts with WordPress

    but it was not sufficiently explicit for a PHP illiterate like myself to work out.

    Thanks for any pointers.

Viewing 2 replies - 1 through 2 (of 2 total)
  • I’m a bit of a PHP noob as well but I was able to get this to work. What you need to do is insert the bits of code he posts to your Main Index Template inside of the loop that generates the posts. So find this code:


    <?php if (have_posts()) : ?>

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

    Then right after that insert:

    <?php static $ctr = 0;
    if ($ctr == "3") { break; }
    else { ?>

    With $ctr == “3” being the number of posts you want to show. Right after that bit there should be a div class=”post” which generates all the post information. Now scroll down to the end of that div. Right before the <?php endwhile; ?>, paste this:

    <?php $ctr++; } ?>

    That’s it! Save the template and check your site. You should see only 3 posts on the home page. All archive and category pages should show whatever you set as the default.

    Thread Starter miromiro

    (@miromiro)

    Thanks mjjack,

    That generates the following error:

    Parse error: parse error, unexpected ‘}’ in ..\..\index.php on line 52

    Which I figure means that I am missing something else. I appreciate the advice, though.

    Cheers

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Limit number of posts on homepage’ is closed to new replies.