WordPress调用最新文章和随机文章的代码脚本

这里麦子在调整一个WP主题的侧边栏,不支持拖拽式小工具调用最新文章和随机文字代码,这里我直接用代码写在侧边栏主题模板中实现。

WordPress调用最新文章和随机文章的代码脚本

1、最新文章

<?php
query_posts('showposts=10&orderby=new'); //showposts=10表示10篇
while(have_posts()): the_post();
?> 
<li><a href="<?php the_permalink(); ?>"target="_blank"><?php the_title() ?></a></li> //CSS样式
<?php endwhile; ?>

2、随机文章

<?php
query_posts('showposts=10&orderby=rand'); //showposts=10表示10篇
while(have_posts()): the_post();
?>
<li><a href="<?php the_permalink(); ?>"target="_blank"><?php the_title() ?></a></li> //CSS样式
<?php endwhile; ?>

当然,根据页面样式情况自定义样式排版布局。

5/5 - (1 vote)
© 版权声明
THE END
喜欢就支持一下吧
点赞7 分享