Support

Home Forums Event Espresso Premium Inputting ads into event list.

Inputting ads into event list.

Posted: April 23, 2013 at 11:12 am


Peter Roesler

April 23, 2013 at 11:12 am

Ok, so we are using an Ad manager and are looking to place a banner ad every 6 events when you are viewing as a list (as the main events page or even in a category).  So if there are 18 events, we want to have a ad show up between 6th and 7th events and 12th and 13th events.  All I need to do  is make this code <?php echo do_shortcode(“[sam id=10]”); ?> appear every 6th event that is listed?  Anybody want to take a stab?  Appreciate it!

Kevin


Dean

April 24, 2013 at 1:30 am

Hi,

You would need to modify the event_list.php file.

Around line 274 where it says

foreach ($events as $event) {

before that add

$i = 0;

after the foreach add something like

$i = ++$i;
if ($i == 6 || $i == 12 || $i == 18) { echo do_shortcode(“[sam id=10]“); }

Obviously you would need to either add more multiples of 6 into the if statement or come up with a better alternative, but this basically counts the events posts and inserts the data every 6 posts.


Tony Warwick

April 24, 2013 at 3:27 am

You can use Modulus division to add in every Nth (in this case 6th) instance. So…

if ($i == 6 || $i == 12 || $i == 18)

would be

if ($i % 6 == 0)

One pitfall with this is that 0 % 3 = 0 so with the counter ($i) starting at 0 you’ll could also get an ad at the beginning of the loop. Deans example adds 1 to $i before the first iteration of the loop anyway so that shouldn’t be an issue. But just in case, to stop that you can use.

if ($i > 0 && $i % 6 == 0)


Tony Warwick

April 24, 2013 at 3:31 am

http://pastebin.com/uexTw9Ai

My own fault for posting code lol


Dean

April 24, 2013 at 4:04 am

Thanks Tony, I learnt something from that!


Peter Roesler

April 30, 2013 at 12:55 pm

Interesting!  I will try this now.  Now what about adding this function into your themes functions.php file so that you can update the plugin without overwriting the customization?  Would you think that is possible?


Dean

May 1, 2013 at 1:11 am

Hi,

Well if you copy the event_list.php and event:list_display.php to the wp-content/uploads/espresso/templates directory and edit them there, any updates will not over write the changes.

I believe that now you can also copy those files to your theme folder as well, with similar results.

The only caveat is if the update brings changes to the template files then you will need to update you modified files with those changes.

The support post ‘Inputting ads into event list.’ is closed to new replies.

Have a question about this support post? Create a new support post in our support forums and include a link to this existing support post so we can help you.

Event Espresso