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增加顶级菜单完成思绪

比方本人创立了一个主题,那么需求在后盾增加一些设置选项,所以就触及到了后盾增加顶级菜单的需要: 复制代...

2015年收费WordPress主题推荐(国际精选)

Enews &ndash; 黑色CMS/Blog双模式WordPress主题 历经将近一个月的工夫,主题作者水冷眸将之首款主题命名为...

WordPress别名已被其它条目应用的处理办法

最近我心血来潮给博客建一个分类别名为&ldquo;WordPress&rdquo;的目录。可是不断提醒&ldquo;别名已被其它条...

WordPress中获取页面链接和题目的相干PHP函数用法解析

get_permalink()(获取文章或页面链接) get_permalink() 用来依据固定衔接前往文章或许页面的链接。在获取...

WordPress中获取指定分类及其子分类下的文章数目

获取特定分类文章数 有时分咱们想获取某个分类(category)下的文章数目,以便在博客的某个中央显示进去。上面...

wordpress wp_list_categories(分类的链接列表)的应用办法

1.用分类做为导航拦 <?php wp_list_categories('depth=2&title_li=0&orderby=name&show_count=0');?> 把这句...

需求提交

客服服务

亿鸽在线客服系统