"I have removed the default styling as myself like most people tend to use their own DIVS, h1, h2, etc, and so it's easier to just apply your DIV's and other styling to the core functioning of the code.
$yoursitename_posts_to_show is a numerical variable passed from where you call the function
Change "yoursitename" throughout the function to something unique to avoid dupe var names in Wordpress. I use my site name as Wordpress wont have used it
//DISPLAY LAST X POSTS
function last_xx_posts($yoursitename_posts_to_show){
if (is_numeric($yoursitename_posts_to_show)){
/* gets number of recent posts limited by the number
you assign to the variable */
query_posts('showposts='.$yoursitename_posts_to_show);
if (have_posts()) :
/*
This shows the var (numerical) you set of number of posts to show
If you will ever show only ONE (1) last recent post, you will need
to add some PHP to allow for "Last 1 post" (not "postS")
/*
echo 'Last '.$yoursitename_posts_to_show.' most recent posts';
while (have_posts()) : the_post(); ?>
By:
Continue Reading - " . the_title('', '', false)."..."); ?>
endwhile; //end loop of all posts
endif; //end if have posts
endif; //end if variable is numeric
}//end function
?>To use this function, copy and paste the above in your wp-content/themes/yourtheme/functions.php file
If you don't have this file you can just make one
Read about that here
http://codex.wordpress.org/Theme_Development#Theme_Functions_File
Then simply use the following code in any of your template files
//show last 5 posts
$yoursitename_posts_to_show = 5;
last_xx_posts($yoursitename_posts_to_show);
?>Set the "5" to however many you want to show.
***IMPORTANT NOTES***
NOTE A
DO NOT call this function with the above code in ANY file where "The_Loop" has already been used.
That is:
while (have_posts()) : the_post(); ?>This includes of course index.php, archive.php, etc
Although, I found I didn't want to anyway as these files already have a bunch of posts, and in single.php the post comments are under the article and that tends to be enough for one page!
Use this code somewhere such as at the bottom of your 404 and perhaps like me you have "pages" like "about this site" that usually
don't have any articles or posts or comments, so using this you can have the last x most recent
NOTE B
THIS WILL override your "Blog pages show at most" setting in Admin -> Settings -> Reading.
So if you set 3 most on one page there, and use the function to display the last 5 posts, it WILL display the last 5 posts!"