ExpressionEngineでは、「ループ」のバージョンで、次のような任意の要素にタグを追加できます。
<li class="{switch='one|two|three|four|five|six'}">
liの最初の反復にはクラス1があり、次の反復は2で、ループは6の後に再びなります。私はワードプレスサイトでこの同様の機能を必要としていますが、それを達成する方法がわかりません。組み込みのワードプレス関数はありますか、それともphpで何らかの関数をコーディングする必要がありますか?
現在、@ Leonardのソリューションを使用するためにこれを使用していますが、クラス「4」はサイクリングではなく何度も繰り返されています
<?php
$argsGallery = array(
'post_type' => 'gallery',
'orderby' => 'menu_order',
'order' => 'ASC'
);
$the_query = new WP_Query( $argsGallery );
// The Loop
while ( $the_query->have_posts() ) : $the_query->the_post();?>
<div class="<?php cycle('four|three|five|two|six|four'); ?> columns">
<div class="thumb">
<a class="jackbox"
data-group="images"
data-thumbnail="<?php the_field('image'); ?>"
data-title="Image One"
data-description="#description_1"
href="<?php the_field('image'); ?>"
>
<div class="jackbox-hover jackbox-hover-black">
<p><?php the_field('image_description'); ?> </p>
</div>
<img
src="<?php the_field('image'); ?>"
alt="responsive lightbox"
/>
</a>
</div>
</div>
<?php
endwhile;
wp_reset_query();
wp_reset_postdata();
?>