Support » Fixing WordPress » Limit number of posts on home page to one (the latest)

  • Resolved Wynnefield


    I apologize for rehashing this as I thought I found a resolution in this forum entry.

    I would like to reopen this discussion for the same purposes as originally intended. I have a programming background, so I thought I could grasp the PHP modifications recommended toward the end of the thread.

    I can see how the entries noted did not work, as the continuation terminator “?>” was excluded from each one (except the example where placed directly within the same PHP segment as the “if (have_posts…”). However, I believe I am inserting this code correctly into the proper index.php file, and it is still not limiting the number of posts on the home page?? (I prefer not to use a plugin for what seems to be a simple solution which I am obviously not be applying correctly.)

    I am using WordPress 2.6.3 with the default theme. I found The Loop in the file /wp-content/themes/default/index.php. It is broken up into two PHP segments as follows:

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

    I inserted the following segment directly above the top entry:

    <!-- Limit the home page to display only one (the latest) post -->
    <?php if(is_page('home') && !is_paged()) { query_posts($query_string.'limit=1'); } ?>

    However, this is not limiting the number of blog posts to one as was previously stated in the original thread. Could someone please identify where I may be inserting this code incorrectly?

    Thank you in advance for your assistance.


Viewing 9 replies - 1 through 9 (of 9 total)
  • <?php query_posts('show_posts=1'); ?>
    <?php if(have_posts()) : /* And so on and so on */ ?>

    I replaced my PHP segment under the XHTML comment with this call to query_posts, and I am receiving the same result, i.e. multiple posts on the home page??


    <!-- Limit the home page to display only one (the latest) post -->
    	<?php query_posts('show_posts=1'); ?>
    	<?php if (have_posts()) : ?>
    		<?php while (have_posts()) : the_post(); ?>

    Did you mean insert this call in addition to the PHP segment I have already applied?

    ty … Wynne

    Do you have another Loop going on?

    (and it’s “showposts” not “show_posts”)

    That was the ticket, doodlebee. Replaced show_posts with showposts and only one post appears on the home page. Thank you muchas.


    Ahhh! I can’t believe I screwed that up. Yep, showposts is correct.

    Although the original issue is resolved, the home page has now placed a link under the single post as follows: « Older Entries. And this link takes me to a 404 Page Not Found as it is trying to find a /page/2 entry?

    What is this link trying to refer to, and if it is supposed to refer to older posts, why is it not referring to the appropriate page names, e.g. /YYYY/MM/page-title, according to the original posts?

    Thank you again for your assistance …


    because query_posts re-edits the loop, and your previous posts and next posts links won’t work. You have to change your query to fix the pagination issues (or, just remove your previous_posts_link and next_posts_link altogether).

    if(is_home() || is_front_page()) {
    $page = (get_query_var('paged')) ? get_query_var('paged') : 1;
         if (have_posts()) : while (have_posts()) : the_post();

    There’s a ton of questions on this already.

    thank you doodle. i appreciate your extra time spent on this issue. although i am not sure i like the “work around”, i will live with it until i have more time to spend learning the PHP guts of these templates.

    i need to work on getting my blog styled before i start digging into these other details. hopefully, there are plenty of id and class definitions in the code to make that task a bit easier than this one.

    again, i appreciate your help.

    … Wynne

    this limits the category of the posts to cat#2531 and only shows one post on the homepage.

    <?php query_posts ($query_string . ‘&cat=2531&showposts=1’); ?>

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Limit number of posts on home page to one (the latest)’ is closed to new replies.