Adding “latest from the blog” to the homepage

I have a big problem and no clue how to solve it 🙂 I want to add a “module” to my homepage (static homepage, not blog posts) that will display the 2 latest blog posts in a very particular way and link back to them. The posts would only display on the homepage and not every other page but the php template used for the page is shared with all the custom pages.

Here is a quick sketch of it

Photo of a paper sketch

A site that does this beautifully on their homepage is SEOmoz ( but i don’t need that much functionality, only blog post title, thumb, excerpt & link to read more )

Screenshot from seomoz.org

Is there a simple way to do this? (plugins, code you can copy/paste from anywhere?) or can I pay someone to write this up for me?

3 Answers
3

Personally, I like using get_posts() (Codex ref) for quick-and-dirty Loops.

In your front-page.php template file, try the following:

<?php

// Create a variable to hold our custom Loop results
$frontpageposts = get_posts( array( 
     'numberposts' => 2 // only the 2 latest posts
) );

// Create output only if we have results
// Customize to suit your HTML markup
if ( $frontpageposts ) { 

     foreach ( $frontpageposts as $fppost ) { 
          // setup postdata, so we can use template tags
          setup_postdata($fppost);
          ?>

          <div <?php post_class(); ?>>
               <h2><a href="https://wordpress.stackexchange.com/questions/16413/<php the_permalink(); ?>"><?php the_title(); ?></a></h2>
               <div class="post-entry">
                    <?php the_post_thumbnail(); ?>
                    <?php the_excerpt(); ?>
               </div>
          </div>

<?php }
} 
?>

Again, you’ll need to modify the HTML markup according to your needs.

Leave a Comment