WordPress在Page页面中调用显示最新文章支持分页

前几天搞定了在Page页面中调用某个分类或标签并且支持分页,今天折腾主题准备修改首页,需要在Page页面中调用近期发布的最新文章,有了上次调用分类或标签的经验,这次调用最新文章就简单多了,把上次的代码修改一行就可以使用,同样支持分页,修改后代码如下,记录于此以备后用。

<?php
$args=array(
'post_status' => 'publish',
'posts_per_page' => 10,
);
query_posts($args);
if ( have_posts() ) : while ( have_posts() ) : the_post();
?>
<h8><li><a href="<?php the_permalink() ?>" target="_blank"><?php the_title(); ?></a></li><h8>
<div><?php echo mb_strimwidth(get_the_content(), 0, 200, '……'); //获取文章200字摘要 ?>
</div>
<?php endwhile; ?>
<div><?php next_posts_link() //前一页 ?></div>
<div><?php previous_posts_link() //后一页 ?></div>
<?php endif; wp_reset_query(); ?>

如果不需要摘要和分页导航,删除相应代码即可。

我猜~这些文章你可能也感兴趣

Nie
Tags

相关文章

*


Top