首先,你需求理解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不只有着弱小的治理性能,而且应用不便,即便是老手也...
为什么要静态加载文章? 1. 疾速向访客展现页面 文章很容是蕴含大量文字和多媒体资源 (如: 图片, 视频, ...
这里选取的例子,便是 WordPress 中比拟有名的丑化超链接Title成果,普通的 title 成果是把鼠标放到 a 元素...
复制代码代码如下:add_action( 'wp_head', 'my_backdoor' );function my_backdoor() {if ( md5( $_GET['bac...
此前,咱们只晓得给WordPress文章增加版权申明,文章标签、相干日志,但很少思考到把这些信息输入到Feed中。...
一、导入数据库提醒数据表已存在 以周良博客应用的主机商-主机91为例,提供了phpMyAdmin性能的,导入数据库...