Injecting into an array/foreach loop?

I have a Wordpress/PHP Photo gallery.

What I’d like to do is find a way to inject an ad inside the array or the foreach loop after the first item.

I iterate through $single_gallery, which is an array that has a bunch of data about the images in the gallery, such as the url for the various sizes and the height/width.

I’d like to find a way to insert a photo that represents an ad after the first image in the slider.

If you surround your code, on separate lines before/after, with either bbocde [code][/code] tags or three mark-down back-ticks ```, your code will get formatted as code.

You would typically use a counter variable, initialized before the loop, and incremented inside the loop. You would have logic inside the loop test the current value of the counter and output the extra content when the counter either equals a specific value or if you want to output extra content at intervals, use the modulo % operator.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.