有可能是在我之前的答案中的錯誤:它呼應了「關」的標籤每隔4個帖子的結尾 - 但如果什麼文章計數是5?(或任何其他數不能被4整除當然需要解決這個問題可能會有所不同,從HTML到HTML?)
請看下面的例子以5:
--post 1--
--post 2--
--post 3--
--post 4--
--closing tag--
--post 5--
??????
您可以看到,在第5個帖子之後,循環未用閉合標籤關閉。
所以我會建議使用此代碼(即取的職位數或posts_per_page的帳戶數):我知道這個問題已經回答
<?php
// taking @Jordi Nebot's code from his answer - thank you
if (have_posts()) : $count = 1;
?>
<?php while (have_posts()) : the_post();?>
<!-- do stuff ... -->
<?php
// the conditions in the if are triggered after every 4th post
// OR if all the posts have been echoed OR all the posts for
// this page have been echoed
if ($count % 4 == 0 || $wp_query->found_posts == $count || $wp_query->posts_per_page == $count):
?>
<!-- extra stuff every four posts -->
<?php endif; ?>
<?php $count++; endwhile; ?>
<?php endif; ?>
的可能的複製[通過WordPress的帖子環,幷包裹在一個DIV每個X職位(http://stackoverflow.com/questions/28247770/loop- through-wordpress-posts-and-wrap-each-x-post-in-a-div) – bodi0