I want a static home page on my wordpress website, I have already set this up and have a bit of content on it, the next step is I want to have 5 recent posts underneath the content. As a normal page this is no problem, as soon as I set the page to a static home page, the posts disappear.
From hours of searching I am aware that I need ‘multiple loops’ in my template, I have found a few examples and tried to implement them in my template with no success. I think I pretty much have the code to bring the recent posts through, bust I think I’m having trouble markup and template tags to actually show the posts.
I hope this isn’t too complicated to understand, and i really appreciate any help, I’ve been at this for 2 days with no progress at all. I can supply any code needed from templates or anything else.
My website – www.completemuscleandfitness.com
Ok, this is what i have so far
<?php
$args = array( 'numberposts' => '5' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.esc_attr($recent["post_title"]).'" >' . $recent["post_title"].'</a> </li> ';
}
which shows this – www.completemuscleandfitness.com
How can i get it to look nice like the other post pages?
First, Welcome!
I guess you use the file
front-page.php
for displaying your homepage.What you have to do, is add the following code into your
front-page.php
:More information about
wp_get_recent_posts()
can be found here.Your template file will look something like the following:
You could try putting this code into
<div id="main">
right before the closing tag</div>
:You can create your own custom homepage template same as
index.php
in your active theme directory.Inside that file you can create your own custom query and iterate through results.
Ex.
This you can think as a sample implementation. You can go further as needed.
Ex.
You can get more information here. And for multiple parameters of the query, refer this.
Unless I’m missing something, I think you are all working much too hard.
Seems to me that the “recent posts” widget should be all you need.
Example:
http://wordpresstest.hjcs.org
The “Recent News” is the “recent posts” widget.
(This site is still under construction–that’s why I have “test” in the sub-domain.)