问题#1
请勿使用
query_posts() 创建二次回路;
it is intended only for modifying the Primary Loop. 要创建次循环,请使用
WP_Query() 或
get_posts():
最好将次要/自定义循环与主查询分开,除非您的目标是修改主要循环。
(如果您需要进一步的指导,请告诉我,我会添加代码示例。我现在看不到您的pastebin内容。)
编辑我看到了几个问题:
你的main loop 内部secondary loop:
<?php while ($featured_query->have_posts()) : $featured_query->the_post(); ?>
<?php while (have_posts()) : the_post(); ?>
在打开主循环之前,您需要关闭您的特色帖子循环:
<?php
// Open featured posts loop
while ($featured_query->have_posts()) : $featured_query->the_post();
// Close featured posts loop
endwhile;
// Open main loop
while (have_posts()) : the_post();
?>
你有一个
extra endif; 循环后:
<?php endwhile;?>
<?php endif; ?>
<div class="clear"></div>
你从不打电话
if ( have_posts() ) 或
if ( $featured_query->have_posts() ). 我会把你的
while 的内部循环
if 条件,但这取决于你。但如果你不这样做,那就把
endif;我要给你一块骨头,让你把肉加进去。您的代码应该如下所示:
<?php
// Define featured posts query
$featured_query = new WP_Query( array(
\'posts_per_page\' => 3,
\'category_name\' => \'featured\'
) );
// Open featured posts loop
if ( $featured_query->have_posts() ) :
while ( $featured_query->have_posts() ) : $featured_query->the_post();
// Featured posts loop markup goes here
?>
<div class="featureportfolio<?php echo $i++;?>">
<?php etc... ?>
</div>
<?php
// Close featured posts loop
endwhile;
endif;
// Reset post() data
wp_reset_postdata();
// Clear/spacer DIV
?>
<div class="clear"></div>
<?php
// Open the main loop
if ( have_posts() ) :
while ( have_posts() ) : the_post();
// Main loop markup goes here
?>
<div id="post-<?php the_ID(); ?>" <?php post_class(\'post format-standard\'); ?>>
<?php etc... ?>
</div>
<?php
// Close main loop
endwhile;
endif;
?>
请注意,无需致电
wp_reset_query(), 因为我们没有触及主查询。