Here’s a simple bit of code (Ok perhaps not simple, but it’s brief) you can stick in your Page template that will show the latest post but should not whack the Page’s content:
<?php $latest = new WP_Query('showposts=1'); ?>
<?php $latest->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
Customize how the post is displayed to suit your needs.
EDIT: Should probably explain the lack of a post loop (ala The Loop). Since we’re only calling up a single post, there’s no need to iterate through the object we’ve created ($latest). But if you need to collect and display more than one post (let’s say it’s 5), modify the code from above to:
<?php $latest = new WP_Query('showposts=5'); ?>
<?php while( $latest->have_posts() ) : $latest->the_post(); ?>
<h2><?php the_title(); ?></h2>
<?php the_content(); ?>
<?php endwhile; ?>
This was very helpful to me. Mega-props!
thanks!!!! This just put me back on schedule to making my portal page. I had just about given up. I am using it in conjunction with “Static Front”
This has been very helpful for what I am trying to do. I just need to take it one step further. I want to only show posts with the category of “News.” Hoping someone can help me out with this.
Try
showposts=5&cat=XX
or something like that.
I messed with that a bit…..but no go. =\
Ok it works if I give it the category number such as cat=3 or cat=5
I’m not really sure where it is assigning the cat variable but i’d like to be able to somehow do this by category name rather than it’s cat number. Any idea?
Wow, that is extremely helpful. However, as bgajus suggested, I would also like to be able to display posts by category. If there is a method to modify that code to display items from a specific category and set a variable from the page to that value… for instance, using the page title as the post category. So that, I could make a specific “Rants” page, that has the page content, and then a certain number of the rants. Man, I need to sit down and learn this PHP stuff. It’s fascinating so far… still confusing as all heck though.
This is exactly what I’m looking for. Is there a way to get it to paginate like on the front page? (only show x number of posts… etc.
how to show the read more link ?