WordPress 默認(rèn)循環(huán)是指在主題模板中用于循環(huán)顯示文章內(nèi)容的代碼結(jié)構(gòu)。以下是一個(gè)典型的 WordPress 默認(rèn)循環(huán)示例:

<?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    <div class="post">
        <h2><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></h2>
        <p><?php the_excerpt(); ?></p>
        <p>Posted on <?php the_time('F jS, Y'); ?> by <?php the_author(); ?></p>
    </div>

<?php endwhile; ?>
<?php else: ?>

    <p>Sorry, no posts to display.</p>

<?php endif; ?>

這個(gè)循環(huán)的工作原理如下:

have_posts():檢查是否有可用的文章。

while (have_posts()):如果有可用的文章,繼續(xù)循環(huán)。

the_post():設(shè)置當(dāng)前文章的數(shù)據(jù),以便在循環(huán)中使用。

在循環(huán)內(nèi)部,使用不同的模板標(biāo)簽來顯示文章的相關(guān)信息,如標(biāo)題、摘要、時(shí)間和作者等。

如果沒有可用的文章,顯示一條消息:“Sorry, no posts to display.”

這個(gè)循環(huán)可以根據(jù)需要進(jìn)行修改,以顯示不同的文章內(nèi)容和格式。但是,大多數(shù) WordPress 主題都會(huì)遵循類似的結(jié)構(gòu)來循環(huán)顯示文章。