Support » Fixing WordPress » Display most recent posts on static homepage – how?

  • I’ve spent the past hour searching and am unable to find solution. I’m looking to create a static homepage with posts below it. I created a page, and set it to be the static homepage in settings > reading; it shows up fine. However, I would like to display my 5 most recent posts below the static homepage (preferably just summary’s of each post).

    Why? Because I’m using wordpress as my website, and when people land on my homepage, I need to have static info that talks about our site (like most sites). I’m not running a straight blog.

    Is this possible? If so, what is the easiest solution for accomplishing this? Seems like a reasonable and simple task, though I’m having a heck of a time finding a solution.

    Thank you in advance for any help you can provide.

Viewing 6 replies - 1 through 6 (of 6 total)
  • Hi actionmedia,

    The easiest way to do this is adding to your static page a get_posts call.

    Here’s one example of a minimal Loop of that kind :

     global $post;
     $myposts = get_posts('numberposts=5&category=1');
     foreach($myposts as $post) :
     <?php the_title(); ?>
     <?php the_content(); ?>
     <?php endforeach; ?>

    You can insert it everywhere in your page : sidebar, bottom … and you can specify how many posts you’ll show (in this case I’ve set up 5), and from which category (you can use too &categoryname=WHATEVER if you prefer).

    Hope that helps.

    Thanks for the quick response. Last question, do I insert this into my main page or do I insert it into index.php? Neither one seems to work.

    Thanks again.

    Just to give another option…

    You can always NOT use a static page and make a ‘sticky’ of the info. That way that sticky post will always show at the top no matter how many newer posts there are.

    Is your main page a WordPress page or an html one ?

    What I’d do is create a new php file called for example homepage.php.

    You want start that file with this statement :

    Template Name: Homepage


    1. copy/paste your index.php, or
    2. copy/paste your html page in it (plus a call for the header and the footer, which you’ll find in any index.php)

    …and add the code I provided avobe, before the call for the footer for example. Save it and upload it into your theme.

    Once that done, create a WordPress page in the text editor, fill it with the static text you want (or with nothing at all in the case that your static text is hardcoded as html), select the page template we just created for it, and publish.

    Now go to the Admin Settings and show that page as the Home of your website.

    The Mr.Marco alternative is cool too, no pain at all.

    The sticky solution is perfect! Didn’t even know that was part of WP. Thanks for the help, really appreciate it.

    uops sorry, for further consultations, avobe, it must be &category_name and not &categoryname as I wrote.

    More here.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Display most recent posts on static homepage – how?’ is closed to new replies.