本文整理自网络,侵删。
首先,你需要了解query_posts函数。该函数的作用就是对文章进行检索、挑选、排序,在其后的LOOP循环中使用经过挑选、排序的文章。例如:
代码如下:
<?php
query_posts('posts_per_page=10&ignore_sticky_posts=1&orderby=rand');
while(have_posts()):the_post();
echo '<li>';the_title();echo '</li>';
endwhile;
wp_reset_query();
<?php
query_posts('posts_per_page=10&ignore_sticky_posts=1&orderby=rand');
while(have_posts()):the_post();
echo '<li>';the_title();echo '</li>';
endwhile;
wp_reset_query();
将随机列出一条文章的标题。至于query_posts的具体参数,请参考开发手册。
接下来,我们就是要通过对query_posts的参数进行调整,挑选出置顶的文章列表了。
相关阅读 >>
详解wordpress开发中get_current_screen()函数的使用
wordpress静态化首页及去除url中的index.html
wordpress添加并整合google自定义搜索实现步骤及代码
更多相关阅读请进入《wordpress》频道 >>