How can I echo out the count of within a foreach loop? I want to change the class of the div below so it’s menu-button-1, menu-button-2 etc etc:
<?php
$pages = get_children(array('orderby' => 'menu_order', 'order' => 'asc'));
foreach($pages as $post) {
setup_postdata($post);
$fields = get_fields();
?>
<div class="menu-button-(insert counter here)">
<a href="<?php echo get_page_link( $post->ID ); ?>"><?php echo $post->post_title; ?></a>
</div>
<?php
}
wp_reset_query();
?>
So I want it to output something like this – <div class="menu-button-1">
then <div class="menu-button-2">
and so on each time it goes through the loop.
1 comment