wordpress经常需要使用到获取最新文章的功能,本文介绍两种方法:
<ul>
<?php query_posts('showposts=10′); ?><!– 指定文章列表条件 –>
<?php while (have_posts()) : the_post(); ?>
<li id="post-<?php the_ID(); ?>">
<span><?php the_time('Y-m-d') ?></span>
<a href="<?php the_permalink() ?>" ><?php the_title(); ?></a>
</li>
<?php endwhile; ?>
</ul>
<h2>最新文章</h2>
<ul>
<?php
$recent_posts = wp_get_recent_posts();
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> ';
}
?>
</ul>