WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] How to restrict the front page to one blog post? (10 posts)

  1. davestolte
    Member
    Posted 6 years ago #

    At http://www.pupntaco.com - how to restrict the front page to one blog post and let the other category archives display five posts?

  2. Teli
    Member
    Posted 6 years ago #

    Do you just want to display the one most recent post on the homepage, or do you want a static front page?

    If it's the former, you may be able to get away with something like <?php if(is_page('home') && !is_paged()) { query_posts('limit=1'); } ?> just before the start of your loop.

    If it's the latter, Options -> Reading, and select the page you'd like to use as your static homepage.

    ~ Teli

  3. davestolte
    Member
    Posted 6 years ago #

    You'll have to forgive me, I'm not a coder...

    It's the former I wish to do (display the one most recent post on the front page)... into which PHP and in what position should I copy & paste that bit?

    Thanks, this is the last hurdle before I take the site live -- :)

  4. davestolte
    Member
    Posted 6 years ago #

    I've tried dropping that code snippet into my index.php in a few places and it doesn't work... any help here would be much appreciated!

  5. Pinoy.ca
    Member
    Posted 6 years ago #

    Put if(is_page('home') && !is_paged()) { query_posts('limit=1'); } only on one spot, right before if (have_posts()) : while (have_posts()) :.

  6. JaneLitte
    Member
    Posted 6 years ago #

    You could get the MaxBlogPress diff't post per page. You have to sign up for a newsletter and endure some blog pimping but I love the plugin. It allows you to set the number of posts you want for each category, archive, search result, etc.

    So set the blog posts to 1 and then use the plugin to set the category pages to show 5 or however many you like. No php coding necessary.

  7. Samuel Wood (Otto)
    Tech Ninja
    Posted 6 years ago #

    Correction to above code: Use this:
    query_posts($query_string.'limit=1');

    Otherwise, pagination won't work.

  8. davestolte
    Member
    Posted 6 years ago #

    Thanks for the help guys, here's what I've tried:

    <?php if(is_page('home') && !is_paged()) { query_posts($query_string.'limit=1'); } if (have_posts()) : ?><?php while (have_posts()) : the_post();?>
    ... didn't work

    if(is_page('home') && !is_paged()) { query_posts($query_string.'limit=1'); }
    <?php if (have_posts()) : ?><?php while (have_posts()) : the_post();?>

    ... didn't work

    <?php if(is_page('home') && !is_paged()) { query_posts($query_string.'limit=1'); } ?>
    <?php if (have_posts()) : ?><?php while (have_posts()) : the_post();?>

    ... didn't work

    Think I'll take a look at that plugin. I'm not meant to code LOL

  9. davestolte
    Member
    Posted 6 years ago #

    JaneLitte, two minutes later, my blog is perfect. Thanks a million!

    -- Dave

  10. Wynnefield
    Member
    Posted 5 years ago #

    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 above.

    I can see how the entries above 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 am using WordPress 2.6.3. 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 previously stated. Could someone please identify where I may be inserting this code incorrectly?

    Thank you in advance for your assistance.

    Wynne

Topic Closed

This topic has been closed to new replies.

About this Topic