wordpress怎样猎取置顶文章列表?
正在WordPress中,或者你心愿挪用设置好的指定文章列表,这一性能若何完成呢?下文就引见完成办法,各人参考应用吧
保举:《WordPress教程》
起首,你需求理解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();
将随机列出一条则章的题目。至于query_posts的详细参数,请参考开发手册。
接上去,咱们就是要经过对query_posts的参数进行调整,筛选出置顶的文章列表了。
代码以下:
$query_post = array( 'posts_per_page' => 10, 'post__in' => get_option('sticky_posts'), 'caller_get_posts' => 1 ); query_posts($query_post); ?> <ul style="display:none;"> <?php while(have_posts()):the_post(); ?> <li><a href="<?php the_permalink(); ?>" title="<?php the_title(); ?>"><?php the_title(); ?></a></li> <?php endwhile; ?> </ul> <?php wp_reset_query();
参数用一个数组的方式放正在$query_post中,要害的参数为'post__in' =>get_option('sticky_posts')以及'caller_get_posts' => 0。
'post__in' => get_option('sticky_posts')确定了该LOOP挪用的是置顶文章列表。'caller_get_posts'的作用是扫除非指定性文章,即除了了置顶文章以外,没有显示其余的文章。(没有增加的状况下,假如置顶文章条款有余'posts_per_page'规则的值,会用最新文章替补完好。)
以上就是wordpress怎样猎取置顶文章列表的具体内容,更多请存眷资源魔其它相干文章!
标签: WordPress wordpress教程 wordpress自学 wordpress技术