Jump to content
Sign in to follow this  
hoystory

Inserting Ad between posts using hooks

Recommended Posts

hoystory

I managed to do this once by directly editing the postloop.php file, but it's a huge pain/re-learning experience for me to go in and hard code that file every time there's an update to PlatformPro. So, this time I tried using the hooks for the first time. I made the following changes to the functions.php file in the Platform Base theme:

add_action('pagelines_loop_post_end', 'inline_amazon_ad');
	
	function inline_amazon_ad(){
	
	if(!$show_ads){ ?>
	
	HTML AD CODE HERE
	
	<?php $show_ads = 1; } ?>
	

Problem: Now the ad appears after each and every post. Can anyone tell me what I can do to make this so the ad only appears after the first post (or the second?)? Is this even possible using the hooks? While my understanding of all this is obviously rudimentary, I'm afraid that by using the hook, I'm placing the code in the loop and where I can't do any counting to limit placing the ad only once. Any help would be much appreciated. Matt

Share this post


Link to post
Share on other sites
Simon

try globaling the variable: (not tested but worth a shot) `add_action('pagelines_loop_post_end', 'inline_amazon_ad');` `function inline_amazon_ad(){` `global $show_ads;` `if(!$show_ads){ ?>` `HTML AD CODE HERE` `<?php $show_ads = 1; } ?>`

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this  

×