对于您的clearfix包装器,您做错了。您有:
$counter = 0;
while ( $loop->have_posts() ) : $loop->the_post();
if ($counter % 4 == 0) :
echo $counter > 0 ? "</div>" : ""; // close div if it\'s not the first
echo "<div class=\'clearfix\'>";
endif;
// BUILDS INTERNAL DIVS
$counter++;
endwhile;
因此,您正在为数字0和数字4的倍数打开div。那么在该语句中,只有当
$counter
大于0。因此,您最终关闭div,然后打开一个可能无法关闭的新div。
你需要做两件事。首先,移动关闭div
在while
陈述第二,包装结束语div
以不同的条件。在此更正:
$counter = 0;
while ( $loop->have_posts() ) : $loop->the_post();
if ($counter % 4 == 0) {
echo "<div class=\'clearfix\'>";
}
// BUILDS INTERNAL DIVS
/**
* Closing div for loop
*
* $counter is more than 0 AND $counter plus 1 is multiple of 4
* OR $counter plus 1 is the total posts found (the plus 1 here is because we start with 0 which counts toward our total)
*/
if ( ($counter > 0 && ($counter+1) % 4 == 0 ) || ($counter+1) == $loop->found_posts ) {
echo "</div>";
}
$counter++;
endwhile;