[resolved] restrict no. of posts (outside a template) (3 posts)

  1. Pirchner
    Posted 11 years ago #

    I have this code on the start page of a site:
    <?php if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
    "><?php the_title(); ?>
    <?php endwhile; else: ?>
    <?php _e('Sorry, no posts matched your criteria.'); ?>
    <?php endif; ?>
    which does what it's meant to do: it shows the titles of recent posts as links.
    Now I want to restrict the number of posts to maybe 5 (the most recent ones, whatever category they may belong to) without limiting the no. of posts shown on the category pages (or elsewhere).
    How can I achieve this goal? (NB: I have searched the archives but all the solutions mentioned there didn't help me at all. Or maybe I'm just a bit too dumb).

  2. moshu
    Posted 11 years ago #

    Solution #1. Set the number of posts shown in Options > Reading to 5, and use one of these plugins to set the number of posts shown elsewehere:
    Solution #2. Use a different loop (query_posts) on the index and limit the number of posts shown there, while setting a high number for the rest (Options > etc.), like monthly and category archives.
    See: http://codex.wordpress.org/The_Loop

  3. Pirchner
    Posted 11 years ago #

    The solution I was looking for seems to be very simple (found it here: http://ifelse.co.uk/archives/2005/04/08/query_posts-redux/)
    All I had to do was put the following line before the Loop:
    <?php query_posts('posts_per_page=5'); ?> e voilà.
    Don't know yet if there are any downsides, but for the moment I'm quite happy :-)

Topic Closed

This topic has been closed to new replies.

About this Topic