I have an array of objects:
Array
(
[0] => stdClass Object
(
[id] => 24
[ban_id] => 163
[ban_url] => http://www.website.com/wp-content/uploads/2014/04/72890.jpg
)
[1] => stdClass Object
(
[id] => 25
[ban_id] => 162
[ban_url] => http://www.website.com/wp-content/uploads/2014/04/46860.jpg
)
[2] => stdClass Object
(
[id] => 26
[ban_id] => 169
[ban_url] => http://www.website.com/wp-content/uploads/2014/04/46871.jpg
)
)
I also have a Wordpress loop:
$count = 0;
while ( have_posts() ) : the_post();
$count++;
$show_ad = $count%3 == 0;
if ( $show_ad ):
echo '<img src="..." alt="" />';
endif;
endwhile;
I would like to display one (or even more, depends on the user's choice) of the images if $show_ad is equal to true (every 3 posts in this case).
For example, 1 different image every 3 posts :
[Wordpress POST 1]
[Wordpress POST 2]
[Wordpress POST 3]
[Image 0]
[Wordpress POST 1]
[Wordpress POST 2]
[Wordpress POST 3]
[Image 1]
[Wordpress POST 1]
[Wordpress POST 2]
[Wordpress POST 3]
[Image 2]
[Wordpress POST 1]
[Wordpress POST 2]
[Wordpress POST 3]
[Image 0]
...
Or another example, 2 different images every 3 posts :
[Wordpress POST 1]
[Wordpress POST 2]
[Wordpress POST 3]
[Image 0]
[Image 1]
[Wordpress POST 1]
[Wordpress POST 2]
[Wordpress POST 3]
[Image 2]
[Image 0]
[Wordpress POST 1]
[Wordpress POST 2]
[Wordpress POST 3]
[Image 1]
[Image 2]
[Wordpress POST 1]
[Wordpress POST 2]
[Wordpress POST 3]
[Image 0]
[Image 1]
...
Any help will be greatly appreciated.
After reviewing your response, i believe the best way to answer your question is to create an incremental variable as well for your banner ads.
Review the following changes to your while loop.
$count = 0;
$banner_count = 0;
while ( have_posts() ) : the_post();
$count++;
$show_ad = $count%3 == 0;
if ( $show_ad ):
//I dont know the name of the banner object so i gave it $banner_object
$banner_url = $banner_object[$banner_count]->ban_url;
echo '<img src="' .$banner_url .'" alt="" />';
//Increment Banner
$banner_count++;
endif;
Hope that helps! Let me know if your looking for something else. If you only have a certain amount banners, then you may want to reset banner_count when it reaches the end of your banners object. See code below
$count = 0;
$banner_count = 0;
while ( have_posts() ) : the_post();
$count++;
$show_ad = $count%3 == 0;
if ( $show_ad ):
$banner_url = $banner_object[$banner_count]->ban_url;
echo '<img src="' .$banner_url .'" alt="" />';
//Increment Banner
$banner_count++;
//If reached the end of the banner count
if($banner_count > count($banner_object)) { $banner_count = 0; }
endif;