i have some trouble with a loop. I need to display some div every 6 iterations
<div class="category_block">
<?php foreach (get_categories() as $cat) : ?>
<div class="category_item">
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
<a href="<?php echo get_category_link($cat->term_id); ?>"><?php echo $cat->cat_name; ?></a>
<span><?php echo $cat->category_count; ?></span>
</div>
<?php endforeach; ?>
</div>
What i need to do?
You can create some variable and can check that variable's value. If that's 6, 12, or 18 etc ... then you can put your etc ... have a code example below:
<div class="category_block">
<?php $counter = 0; ?>
<?php foreach (get_categories() as $cat) :
$counter++;
?>
<div class="category_item">
<?php if($counter % 6 == 0) {>
<div class="custom-div"></div>
<?php } ?>
<img src="<?php echo z_taxonomy_image_url($cat->term_id); ?>" />
<a href="<?php echo get_category_link($cat->term_id); ?>"><?php echo $cat->cat_name; ?></a>
<span><?php echo $cat->category_count; ?></span>
</div>
<?php endforeach; ?>
</div>
Hope, that solves your issue.