query_posts函数是WordPress查询文章里面比较常用的函数,当然WordPress调用文章函数有很多,今天主题君主要给大家讲解下query_posts这个函数。
query_posts的基本用法
<?php query_posts( $args ); ?>
<?php while ( have_posts() ) : the_post(); ?>
...
<?php endwhile; ?>
<?php wp_reset_query(); ?>
query_posts函数添加在主循环前,如果后面还有循环函数,需要在循环结束后增加<?php wp_reset_query(); ?>来重置query。
使用query_posts获取多属性文章
cat = 1 就是获取分类为1的文章、posts_per_page是文章数量
<?php
$args=array(
'cat' => '1',
'posts_per_page'=> '5',
'orderby'=> 'date'
);
?>
<?php while ( have_posts() ) : the_post(); ?>
...
<?php endwhile; ?>
<?php wp_reset_query(); ?>
- orderby=date?按发布日期排序
- orderby=modified 按修改时间排序
- orderby=ID 按文章ID排序
- orderby=comment_count 按评论最多排序
- orderby=title 按标题排序
- orderby=rand 随机排序
文章标题:WordPress查询文章函数:query_posts
文章链接:https://www.jitheme.com/2487.html
更新时间:2024年03月28日
1.本站大部分内容均收集于网络!若内容若侵犯到您的权益,请发送邮件至:service@jitheme.com,我们将第一时间处理!
2.资源所需价格并非资源售卖价格,是收集、整理、编辑详情以及本站运营的适当补贴,并且本站不提供任何免费技术支持。
3.所有资源仅限于参考和学习,版权归原作者所有,更多请阅读极(子)主题网络服务协议。