Support » Fixing WordPress » Limiting the number of posts shown on homepage

  • jimday1982

    (@jimday1982)


    I’m hoping someone can help me limit the number of posts that are shown on my home page to 5. I thought I found the code I needed to make it work, but when I navigate to the second page (older posts), I get a page not found error. The code I’m using for my main index template is below:

    <?php get_header(); ?>
    
    		<!-- main -->
    		<div id="main" class="grid_8">
    
    <?php 
    
    //The line below is what I added - it does only show 5 posts on the home page, but I get a 404 error when clicking //"older posts"
    //query_posts($query_string.'&posts_per_page=5');
    
    if (have_posts()) : while (have_posts()) : the_post(); ?>
    
    			<h2><a href="<?php the_permalink(); ?>" rel="bookmark" title="Permanent Link to <?php the_title_attribute(); ?>"><?php the_title(); ?></a></h2>
    
    			<p class="post-info">Posted by <?php the_author(); ?> on <?php the_time('F j, Y'); ?></p>
    
    			<?php the_content('Read the rest of this entry...'); ?>
    
    <?php the_tags('<p>Tags: ', ', ', '</p>'); ?>
    
    			<p class="postmeta">
    			<a href="<?php the_permalink(); ?>" class="readmore">Read more</a> |
    			<a href="<?php comments_link(); ?>" class="comments">Comments (<?php comments_number('0','1','%'); ?>)</a> |
    			<span class="date">Filed under <?php the_category(', ') ?></span>
    			</p>
    
    <?php endwhile; ?>
    
    			<div class="alignleft"><?php next_posts_link('&laquo; Older Entries'); ?></div>
    			<div class="alignright"><?php previous_posts_link('Newer Entries &raquo;'); ?></div>
    
    	<?php else : ?>
    
    		<h2>Not Found</h2>
    
    		<p>Sorry, but you are looking for something that isn't here.</p>
    
    	<?php endif; ?>
    
    		<!-- main ends -->
    		</div>
    
    <?php get_sidebar(); ?>
    <?php get_footer(); ?>

    Thanks so much for your help.

Viewing 2 replies - 1 through 2 (of 2 total)
  • stvwlf

    (@stvwlf)

    Hi

    you don’t need to modify any code

    Admin / Settings / Reading
    Blog pages show at most xx posts

    Thread Starter jimday1982

    (@jimday1982)

    Oh wow, I totally missed that! Thanks so much!

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