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 dynamic_sidebar()函数应用办法

dynamic_sidebar()函数用来支持自定义sidebar侧边栏,能够自定义Widget插件,比方为侧边栏增加最近文章,文...

WordPress获取指定分类文章数量的办法

本文实例讲述了WordPress获取指定分类文章数量的办法。分享给大家供大家参考。详细完成办法如下: 将以下PH...

在WordPress中获取数据库字段内容和增加主题设置菜单

get_option() 函数应用技巧 get_option()这个函数,实际上咱们在整合后盾性能的时分常常会用到的一个函数,...

WordPress 不同分类目录调用不同模板的办法

wordpress不同分类调用不同模板文件 用wordpress做站特地是企业站的时分,多个分类的内容不同需求显示的页面...

wordpress非插件完成xml格局网站地图

废话不多说,间接上代码复制代码代码如下:<?phprequire('./wp-blog-header.php');header("Content-type: te...

深化解析WordPress中加载模板的get_template_part函数

最近钻研民间主题 Twenty Eleven ,有一些货色网上现成的中文材料不好找,在博客里记录上去,算是分享,也算...

需求提交

客服服务

亿鸽在线客服系统