Display recent wordpress posts on a page
I would like to开发者_StackOverflow display all of the recent wordpress posts in a page on wordpress. I have tried a few plugins with not much luck. I would simply like to display the title and excerpt of the last 10 posts. Can someone point me in the right direction?
Any help is appreciated.
Thanks, Kevin
Create recentpost.php and save it on the same directory with your current theme
This should be the basic content of your recentpost.php
//-------start here
<?php
/*
Template Name: Recent Post
*/
?>
<?php
get_header();
?>
<h2>Recent Posts</h2>
<ul>
<?php
$args = array( 'numberposts' => '10' );
$recent_posts = wp_get_recent_posts( $args );
foreach( $recent_posts as $recent ){
echo '<li><a href="' . get_permalink($recent["ID"]) . '" title="Look '.$recent["post_title"].'" >' . $recent["post_title"].'</a> </li> ';
}
?>
</ul>
<?php
get_sidebar();
get_footer();
?>
//--------end here
And on your Admin Control page, create new page, and on the right side you can select the template "Recent Post".
This piece of code should display the title and excerpt of the last 10 post
<?php
$arguments = array('numberposts' => '10');
$posts = wp_get_recent_posts($arguments);
foreach($posts as $post){
the_title();
the_excerpt();
}
?>
精彩评论