- This topic is empty.
Viewing 4 posts - 1 through 4 (of 4 total)
Viewing 4 posts - 1 through 4 (of 4 total)
- The forum ‘Back End’ is closed to new topics and replies.
The forums ran from 2008-2020 and are now closed and viewable here as an archive.
Hi Everyone, I’m fairly new to wordpress and php so this might be a silly question, but here it goes.
I have a static custom home page for my wordpress site and I’m trying to include two things on the page; the content for my “home” page as well as the last 3 most recent posts. So this is what’s in my index.php file:
Read the rest of this page →'); ?>
Pages: ', '', 'number'); ?>
">
by
So the problem is, that the home page text and the most recent post shows up, then below that, the home page text shows up again instead of the next oldest post. I understand that the loop is going back to grab the home page content again instead of the other posts but I don’t know how to tell it just to grab the posts.
I’m certain there’s a simple solution for my problem, but I just can’t figure it out. Can someone please help?
Thanks
Samantha
You’re almost there! Change your query to this:
Thank you Doc, but it still doesn’t seem to be working properly. I’ve fiddled around with it a bit and now have just one latest post showing, but I would like to display 3.
After a lot of frustration, I referred back to the wordpress codex site. I re-wrote the whole section of code and it seems to work properly now. YAY!
// The Query
$the_query = new WP_Query( 'posts_per_page=3' );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();
// The Title
echo '
the_permalink();
echo '">';
the_title();
echo '
';
// The Author
echo 'by ';
the_author();
echo '
';
// The excerpt
echo '';
the_excerpt();
echo '
';
// The date
echo '';
the_time('F j, Y');
echo ' ';
comments_popup_link('No Comments', '1 Comment', '% Comments');
echo '
';
endwhile;
// Reset Post Data
wp_reset_postdata();
?>