現在、親の行にある2つのdivをphpでラップしていますが、これはうまく機能しています。PHPを使用して2つのdivのレイアウトを変更
しかし、私がする必要があるのは、3rd & 4th, 7th & 8th
などのdivが異なるレイアウトを持つようにすることです。これは現在、親行の2つのdivをすべてラップするコードです。
<?php
if(have_rows('products')) :
$counter = 1;
$i = 0;
?>
<div class="o-table l-grid-half">
<?php while(have_rows('products')) :
the_row();
if ($i > 0 && ($i % 2 == 0)) {
// close row and open new row
?>
</div>
<div class="o-table l-grid-half">
<?php } ?>
<div class="o-table-cell l-grid-half__item ">
<div class="o-table-cell l-grid-half__item ">
<img src="<?php the_sub_field('product_image'); ?>"/>
</div>
<div class="o-table-cell o-table-vt l-grid-half__item o-full-sm-pd o-roman l-product__item o-bg-item-<?php echo($counter);?>">
<h3 class="hd-panel-sm"><?php the_sub_field('product_heading'); ?></h3>
<?php the_sub_field('product_summary'); ?>
<a href="<?php the_sub_field('product_link'); ?>" class="link-std clearfix"><i class="icon-right-open"></i><span>Find out more</span></a>
</div>
</div>
<?php
$i++;
$counter++;
endwhile;
?>
</div>
<?php endif;
?>
私が既存のコードにラップしようとしたことはすべて、スクリプトを壊しました。
私はhtmlのは、この(簡易版)のようになりたい最終目標:
<div class="o-table im-the-parent-row">
<div class="o-table-cell im-the-child-div">
<img src="img-on-the-left.jpg"/>
<p>text on the right</p>
</div>
<div class="o-table-cell im-the-child-div">
<img src="img-on-the-left.jpg"/>
<p>text on the right</p>
</div>
</div>
<div class="o-table im-the-parent-row">
<div class="o-table-cell im-the-child-div">
<p>text on the left</p>
<img src="img-on-the-right.jpg"/>
</div>
<div class="o-table-cell im-the-child-div">
<p>text on the left</p>
<img src="img-on-the-right.jpg"/>
</div>
</div>
更新コード:
<?php
if(have_rows('products')) :
$counter = 1;
$i = 0;
?>
<div class="o-table l-grid-half">
<?php while(have_rows('products')) :
the_row();
if ($i > 0 && ($i % 2 == 0)) {
// close row and open new row
?>
</div>
<div class="o-table l-grid-half">
<?php } ?>
<!--Row 3&4, 7&8 have the image on the left -->
<?php if($i > 0 && (($i % 4 == 0) || (($i+1) % 4 == 0))) { ?>
<div class="o-table-cell l-grid-half__item ">
<div class="o-table-cell o-table-vt l-grid-half__item o-full-sm-pd o-roman l-product__item o-bg-item-<?php echo($counter);?>">
<h3 class="hd-std-sm"><?php the_sub_field('product_heading'); ?></h3>
<?php the_sub_field('product_summary'); ?>
<a href="<?php the_sub_field('product_link'); ?>" class="link-std clearfix"><i class="icon-right-open"></i><span>Find out more</span></a>
</div>
<div class="o-table-cell l-grid-half__item ">
<img src="<?php the_sub_field('product_image'); ?>"/>
</div>
</div>
<?php } else {?>
<!--Row 1&2, 5&6 have the image on the right -->
<div class="o-table-cell l-grid-half__item ">
<div class="o-table-cell l-grid-half__item ">
<img src="<?php the_sub_field('product_image'); ?>"/>
</div>
<div class="o-table-cell o-table-vt l-grid-half__item o-full-sm-pd o-roman l-product__item o-bg-item-<?php echo($counter);?>">
<h3 class="hd-std-sm"><?php the_sub_field('product_heading'); ?></h3>
<?php the_sub_field('product_summary'); ?>
<a href="<?php the_sub_field('product_link'); ?>" class="link-std clearfix"><i class="icon-right-open"></i><span>Find out more</span></a>
</div>
</div>
<?php } ?>
<?php
$i++;
$counter++;
endwhile;?>
</div>
<?php endif;
?>
キーワード 'nth-child()'セレクタにはおそらくCSSを使用しているはずです。 – CBroe