WordPress.org

Ready to get started?Download WordPress

Forums

Display most recent posts on static homepage - how? (7 posts)

  1. actionmedia
    Member
    Posted 5 years ago #

    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.

  2. Dunkkan
    Member
    Posted 5 years ago #

    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 :

    <?php
     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.

  3. actionmedia
    Member
    Posted 5 years ago #

    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.

  4. MrMarco
    Member
    Posted 5 years ago #

    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.

  5. Dunkkan
    Member
    Posted 5 years ago #

    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 :

    <?php
    /*
    Template Name: Homepage
    */
    ?>

    Then

    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.

  6. actionmedia
    Member
    Posted 5 years ago #

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

  7. Dunkkan
    Member
    Posted 5 years ago #

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

    More here.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.