wordpress获取置顶文章列表的方法有哪些?

784
98素材网VIP特权升级VIP整站资源永久免费下载 点我升级VIP
标签 :wordpress置顶2020-01-04

详情介绍

在WordPress中,或许你希望调用设置好的指定文章列表,这一功能如何实现呢?下文就介绍wordpress获取置顶文章列表的方法。

首先,你需要了解query_posts函数。该函数的作用就是对文章进行检索、挑选、排序,在其后的LOOP循环中使用经过挑选、排序的文章。例如:

wordpress获取置顶文章列表的方法有哪些?

代码如下:

$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_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'的作用是排除非指定性文章,即除了置顶文章之外,不显示其他的文章。

以上就是wordpress获取置顶文章列表方法的详细内容。


1、升级本站永久VIP,仅需【49】元即可升级 ! ! ! (升级后永久享受整站资源全部免费下载)

2、站内资源均可通过签到等任务进行免费兑换。

3、站内资源均来源于网络公开发表文件或网友投稿发布,如侵犯您的权益,请联系管理员处理。

4、本站所分享的源码、模板、软件工具等其他资源,都不包含技术服务,请大家谅解!

5、所有资源均收集于互联网仅供学习、参考和研究,请理解这个概念,所以不能保证每个细节都符合你的需求,也可能存在未知的BUG与瑕疵,因本站资源均为可复制品,所以不支持任何理由的退款兑现(特殊情况可退积分),请熟知后再支付下载!

评论(0)条