【发布时间】:2020-08-11 05:57:28
【问题描述】:
我是 Wordpress 的新手,但我遇到了帖子循环的问题。我需要先在不同的容器中发布,然后再在其他容器中发布。 我想做这样的模板:
<div class="container-fluid">
<div class="row">
first post
</div>
</div>
<div class="container">
<div class="row">
<div class="col-12">
posts
</div>
</div>
</div>
我做了这样的事情,但效果不佳:
<?php if (have_posts()) : $postCounter = 0 ?>
<?php while (have_posts()) : $postCounter++ ?>
<?php foreach (array(the_post()) as $post): ?>
<?php if ($postCounter == 1): ?>
<div class="container-fluid">
<div class="row">
<h1>Tu będzie pierwszy post</h1>
</div>
</div>
<?php endif; ?>
<div class="container">
<div class="row">
<div class="col-12">
<?php if ($postCounter > 1): ?>
<h1>Tu będzie kolejny post</h1>
<?php endif; ?>
</div>
</div>
</div>
<?php endforeach ?>
<?php endwhile; ?>
<?php endif; ?>
【问题讨论】: