3 回答
TA贡献1820条经验 获得超10个赞
我们只需要更改function.php中的代码,如下所示。
<?php
$i=0;
foreach ( $termchildren as $child ) {
$term = get_term_by( 'id', $child, $taxonomy_name );
$image = get_field('featured_image', $term);
if($i % 2){ ?>
<div class="row">
<div id="product-cat <?php echo $term->slug ?>">
<div class="two-col product-cat-image">
<img src="<?php echo $image ?>">
</div>
<div class="two-col product-cat-details">
<?php
echo '<h4>'. $term->name .'</h4>';
echo '<p>'. $term->description .'</p>';
echo '<a class="product-cat-button" href="' . get_term_link( $child, $taxonomy_name ) . '">See Products</a>';
?>
</div>
</div>
</div>
<?php } else {?>
<div class="row">
<div id="product-cat <?php echo $term->slug ?>">
<div class="two-col product-cat-details">
<?php
echo '<h4>'. $term->name .'</h4>';
echo '<p>'. $term->description .'</p>';
echo '<a class="product-cat-button" href="' . get_term_link( $child, $taxonomy_name ) . '">See Products</a>';
?>
</div>
<div class="two-col product-cat-image">
<img src="<?php echo $image ?>">
</div>
</div>
</div>
<?php }
$i++;
}
?>
希望现在你得到了所有的东西,让我知道还有什么需要帮助的。
TA贡献1898条经验 获得超8个赞
您需要添加以下 css 以实现所需的输出:
当.product-cat发现奇数div 适用order: 1;于图像容器(.product-cat-image)和order: 2;细节容器(.product-cat-details)
当.product-cat找到的 div 也适用order: 2;于图像容器(.product-cat-image)和order: 1;细节容器(.product-cat-details)
.product-cat:nth-child(odd) .product-cat-image{
-webkit-order: 1;
order: 1;
}
.product-cat:nth-child(odd) .product-cat-details{
-webkit-order: 2;
order: 2;
}
.product-cat:nth-child(even) .product-cat-image{
-webkit-order: 2;
order: 2;
}
.product-cat:nth-child(even) .product-cat-details{
-webkit-order: 1;
order: 1;
}
- 3 回答
- 0 关注
- 261 浏览
添加回答
举报