Support » Plugins and Hacks » Display latest post on home page

Display latest post on home page

  • I’ve looked at the documentation for “The WordPress Loop”, but I can’t seem to get a definitive answer for this. I’d like my home page to display my latest post as if someone had clicked a permalink to go to it, rather than listing a number of posts. Although there is a form where you can tell WordPress to display a specified number of posts on the home page, setting this to one does not help because the function is_single() still does not return true. Has anyone here tried doing this before? Thanks for any help.

Viewing 4 replies - 1 through 4 (of 4 total)
  • There are probably other ways of doing this, but … In your index.php for whatever theme you’re using you’ll see that the main loop which displays all the posts looks something like this:

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

    Simply adding a break statement within the loop should work:

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

    Just make sure the break statement is the last thing before the endwhile.

    I have actually tried this – unfortunately it also does not cause the function is_single() to evaluate true. This is important becuase I would like the comments and various other features associated with viewing a single post to be present on the page.

    Have a look at this thread:


    According to the doco at http://codex.wordpress.org/Template_Tags/get_posts, the following should work, if you put it in place of the current loop:

    $posts = get_posts('numberposts=1');
    foreach ($posts as $post):

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Display latest post on home page’ is closed to new replies.