将粘性帖子作为循环中的第一篇帖子-WordPress
我想就WordPress sticky posts功能的一个问题获得帮助 我想不出如何使杆柱粘到循环的开头。我有一个类似于他的循环:将粘性帖子作为循环中的第一篇帖子-WordPress,wordpress,sticky,Wordpress,Sticky,我想就WordPress sticky posts功能的一个问题获得帮助 我想不出如何使杆柱粘到循环的开头。我有一个类似于他的循环: <?php query_posts('cat=10&posts_per_page=3');?> <?php if (have_posts()) : ?> <?php while (have_posts()) : the_post(); ?> 我希望它能像这样工作: 粘帖 普通职务 普通职务 而不是: 普
<?php query_posts('cat=10&posts_per_page=3');?>
<?php if (have_posts()) : ?>
<?php while (have_posts()) : the_post(); ?>
我希望它能像这样工作:
- 粘帖
- 普通职务
- 普通职务
- 普通职务
- 粘帖
- 普通职务
谢谢你的帮助 我在我的演示网站上测试了这个。默认顺序应为: -粘的 -普通的 -普通的 默认顺序不是 -普通的 -粘的 -普通的 我建议用其他主题测试它,比如twentyten。 从那里可能是基本的调试 选中此项:
我在我的演示网站上测试了这个。默认顺序应为: -粘的 -普通的 -普通的 默认顺序不是 -普通的 -粘的 -普通的 我建议用其他主题测试它,比如twentyten。 从那里可能是基本的调试 选中此项: 我的解决方案在这里 我提出了两个问题,在这种情况下,我不使用分页可能会有所帮助
$sticky=get_选项('sticky_posts');
$args\u nonsticky=数组(
“展示帖子”=>-1,
'post__not_in'=>$sticky
);
$args\u sticky=array(
“每页帖子数”=>-1,
'post_uuin'=>$sticky
);
$thew\u query\u sticky=新的WP\u查询($args\u sticky);
$thew_query_nonsticky=新的WP_查询($args_nonsticky);
如果(!$the\u query\u sticky->have\u posts()&&&!$the\u query\u nonsticky->have\u posts()){
//回音“未找到帖子”;
}否则{
如果($sticky[0]){
while($thequery\u sticky->have\u posts()):$thequery\u sticky->the\u post();
//如果是这样的话。。。
结束时;
}
while($the_query_nonsticky->have_posts()):$the_query_nonsticky->the_post();
//不粘
结束时;
}
我的解决方案在这里
我提出了两个问题,在这种情况下,我不使用分页可能会有所帮助
$sticky=get_选项('sticky_posts');
$args\u nonsticky=数组(
“展示帖子”=>-1,
'post__not_in'=>$sticky
);
$args\u sticky=array(
“每页帖子数”=>-1,
'post_uuin'=>$sticky
);
$thew\u query\u sticky=新的WP\u查询($args\u sticky);
$thew_query_nonsticky=新的WP_查询($args_nonsticky);
如果(!$the\u query\u sticky->have\u posts()&&&!$the\u query\u nonsticky->have\u posts()){
//回音“未找到帖子”;
}否则{
如果($sticky[0]){
while($thequery\u sticky->have\u posts()):$thequery\u sticky->the\u post();
//如果是这样的话。。。
结束时;
}
while($the_query_nonsticky->have_posts()):$the_query_nonsticky->the_post();
//不粘
结束时;
}
在我的“工具箱”主题的默认index.php中,顺序将粘性文章放在顶部,但在我自己的WP_查询中,我无法将其设置为分类过滤器(例如,类别的分类过滤器)以这种方式断开。您可以在查询参数中添加:'tax\u query'=>array(数组('taxonomy'=>get\u queryed\u object()->taxonomy,'field'=>id',terms'=>get\u queryed\u object()->term\u id))在我的“工具箱”主题的默认index.php中,顺序将粘性帖子放在顶部,但在我自己的WP_查询中,我无法使分类法过滤器(例如,类别)以这种方式被破坏。您可以向查询参数中添加:“tax\u query”=>array(array('taxonomy'=>get\u queryed\u object()->taxonomy,'field'=>id','terms'=>get\u queryed\u object()->term\u id))
$sticky = get_option( 'sticky_posts' );
$args_nonsticky = array(
'showposts' => -1,
'post__not_in' => $sticky
);
$args_sticky = array(
'posts_per_page' => -1,
'post__in' => $sticky
);
$the_query_sticky = new WP_Query($args_sticky);
$the_query_nonsticky = new WP_Query($args_nonsticky);
if(!$the_query_sticky->have_posts() && !$the_query_nonsticky->have_posts()){
//echo '<h1>NO POSTS FOUND</h1>';
}else{
if ( $sticky[0] ) {
while ($the_query_sticky->have_posts()) : $the_query_sticky->the_post();
//sticky if so...
endwhile;
}
while ($the_query_nonsticky->have_posts()) : $the_query_nonsticky->the_post();
// non sticky
endwhile;
}