0

My SimplePie install is a straight-up linux install. (no wordpress or anything)

I'm trying to add a banner in-between my feed articles. For instance if I have 10 feed articles displaying per page, I'd like to add one after the 5th one.

Any help is much appreciated... My feed page is very basic and visible here:

In case you're unfamiliar with SimplePie code, here's basically a very similar code to what makes up the page above:

To display how many articles I want on each page, I use:

// Set our paging values

$start = (isset($_GET['start']) && !empty($_GET['start'])) ? $_GET['start'] : 0; // Where do we start?
$length = (isset($_GET['length']) && !empty($_GET['length'])) ? $_GET['length'] : 10; // How many per page?
$max = $feed->get_item_quantity(); // Where do we end?
slm
  • 15,396
  • 12
  • 109
  • 124

1 Answers1

1

In your loop that outputs the articles, you can use a counter and the modulus operator:

$counter = 0;
foreach ($feed->get_items($start, $length) as $key=>$item) {
   if ($counter % 5 == 0) {   // use modulus operator
      // display banner
   }
   // ...
   $counter++;
}

See php modulus in a loop article. The code above will display the banner when $counter = 0, 5, 10, etc.

Community
  • 1
  • 1
Revent
  • 2,091
  • 2
  • 18
  • 33