だから私は PHP を使用して、div 要素を開くか閉じる必要がある n 番目のループの基準でいくつかのコンテンツを生成しようとしています。したがって、私の目標は、ページに 8 つの要素を表示し、9 番目の要素に表示することです。8 番目の要素の div を閉じ、9 番目の要素に画像があれば新しいものを開きたいと思います。これが私のコードです。
$images; // object
$i = 1;
echo '<div class="outer-container">';
while ( $images->have_images() ) {
if ( $i === 1 ) {
echo '<div class="inner-container">';
}
echo 'content here';
if ( $i === 8 || $images->total === $images->current + 1 ) {
echo '</div><!--.inner-container-->';
}
$i++;
}
echo '</div><!--.outer-container-->';
最終結果は次のようになります。
<div class="outer-container">
<div class="inner-container">
content here
content here
content here
content here
content here
content here
content here
content here
</div><!--.inner-container-->
<div class="inner-container">
content here
content here
content here
</div><!--.inner-container-->
</div><!--.outer-container-->
私は周りを検索し、おそらくモジュラスを使用する必要があるという結論に達しましたが、それをコードに組み込む方法がわかりません。
ご覧いただきありがとうございます。