最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

theme development - Infinite loop when nesting have_posts()

programmeradmin4浏览0评论

I need to create blocks of posts in my theme. So far, I only thought of one possible implementation - a nested loop:

The Code

for ($i = 0; have_posts(); $i++) {
    for ($j = 0; have_posts() && $j < 100; $j++) {
        the_post();
        echo "<p>$i, $j</p>";
    }
}

The Problem

Alas, this code generates an endless loop. have_posts() returns true in the loop on the outside every time.

What I tried

Using the_content() in the outside loop. It doesn't solve the problem and makes the inside loop iterate one time less. THat's the only thing I thought of.

发布评论

评论列表(0)

  1. 暂无评论