WordPress如何调用最新文章或随机文章

追格官方小助手/ 2022年10月07日/ WordPress/ 浏览 1101

追格用户群里,常见咨询WordPress如何调用最新文章或随机文章,小编简单弄下代码,具体样式和位置可按添加。


WordPress随机文章


<?php
query_posts('showposts=5&orderby=rand'); //showposts=5代表5篇文章
while(have_posts()): the_post();
?>
<li><a href="<?php the_permalink(); ?>"target="_blank"><?php the_title() ?></a></li> //CSS样式按需修改
<?php endwhile; ?>


WordPress最新文章


<?php
query_posts('showposts=5&orderby=new'); //showposts=5代表5篇文章
while(have_posts()): the_post();
?> 
<li><a href="<?php the_permalink(); ?>"target="_blank"><?php the_title() ?></a></li> //CSS样式按需修改
<?php endwhile; ?>


发表评论

暂无评论,抢个沙发...

客服 工单