Inserting a counter into a foreach loop
-
ok, I’ll do my best to explain what i need. I am using this loop to get the image paths and then I build the div tags and links.
‘
<?php wp_reset_query(); ?><?php query_posts(‘category_name=Photos&posts_per_page=6’); ?>
<?php if (have_posts()) : while (have_posts()) : the_post(); ?>
<?php $images = get_post_meta($post->ID, ‘coverthumb’, false); ?>
<?php
foreach($images as $image) {
echo ‘<div id=”photosWrapper”>’;
echo ‘<div id=”photos”>’;
echo ‘<a href=”‘;
echo ”.the_permalink().'”>’;
echo ‘<img src=’.$image.’.jpg rel=”shadowbox” border=”0″ class=”a”/>’;
echo ”;
echo ‘</div>’;
echo ‘</div>’;
}
?><?php endwhile; ?>
<?php endif; ?>
‘
I want to be able to put in a counter (e.g. $i=0; i++;) in the foreach loop so that I can use different styles depending on which image is being loaded. Basically, I want every 3rd image to have a different id.Any help would be greatly appreciated. I’m pretty sure it has something to do with adding => $value to the end of the foreach loop but there is nothing to put in there so that just kicks back an error.
- The topic ‘Inserting a counter into a foreach loop’ is closed to new replies.