You are trying to use count()
in a way that this function is not intended. Per the PHP documentation:
Counts all elements in an array, or something in an object.
http://php.net/manual/en/function.count.php
What you need to do is create a counter variable that increments within your foreach
loop, and when it hits 3 outputs the banner. Your code might look something like this:
<?php
$stories = Wo_GetPosts(array('limit' => 10));
// No stories; output error
if (count($stories) <= 0)
echo Wo_LoadPage('story/no-stories');
// Stories exist; show them!
} else {
$count = 0;
// Loop through $stories
foreach ($stories as $wo['story']) {
// Increment the value of $count by +1
$count++;
if ($count == 3) {
// Output my Banner here
}
echo Wo_LoadPage('story/content');
}
}
?>
One thing I would note is that the above code only outputs a banner one time; when the value of $count
is 3
. You could adjust this to run ever 3rd story by changing the match from if ($count ==3)
to if ($count % 3 == 0)
which essentially reads as If the value of $count is divisible by 3
.