Jump to content
Sign in to follow this  
barroncuadro

how to insert ad space after 1st/2nd post in posts page?

Recommended Posts

barroncuadro

Hi all, Do you have a suggestion for inserting ad space after the 1st/2nd posts in the posts page? I wanted to use widgets and I have that part set up, but is there a way to target JUST the area after the 1st post, and also after the 2nd post using available hooks? The only markup I have in functions.php so far is:

		if ( function_exists('register_sidebar') )
			register_sidebar(array(
			'name' => 'Ad After Post 1',
			'before_widget' => '<div class="adSpace adPost1">',
			'after_widget' => '</div>',
			'before_title' => '<h2>',
			'after_title' => '</h2>',
		));
	
			if ( function_exists('register_sidebar') )
		register_sidebar(array(
			'name' => 'Ad After Post 2',
			'before_widget' => '<div class="adSpace adPost2">',
			'after_widget' => '</div>',
			'before_title' => '<h2>',
			'after_title' => '</h2>',
		));
	
	if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Ad After Post 1") ) :
	
	endif;
	
	if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Ad After Post 2") ) :
	
	endif; 

Share this post


Link to post
Share on other sites
cmunns

Yes you could use the `'pagelines_loop_post_end'` as the hook location. then wrap the new widget/function with a conditional. if ($count ==1){}

Share this post


Link to post
Share on other sites
barroncuadro

I had this working for a second (but not anymore), but I noticed it's within the post area itself when using this hook. Is there a hook that will hit right after the post area? Additionally, where in the template setup section is pagelines_loop_post_end listed? Couldn't find it. Here's what I have so far but it's totally incorrect. any hints? thanks in advance:

		if ( function_exists('register_sidebar') )
			register_sidebar(array(
			'name' => 'Ad After Post 1',
			'before_widget' => '<div class="adSpace adPost1">',
			'after_widget' => '</div>',
			'before_title' => '<h2>',
			'after_title' => '</h2>',
		));
	
		if ( function_exists('register_sidebar') )
			register_sidebar(array(
			'name' => 'Ad After Post 2',
			'before_widget' => '<div class="adSpace adPost2">',
			'after_widget' => '</div>',
			'before_title' => '<h2>',
			'after_title' => '</h2>',
		));
	
	add_action('pagelines_loop_post_end', 'ad_space_after_posts');
	function ad_space_after_posts(){
	
		if ($count ==1){
			if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Ad After Post 1") ) :
	
			endif;
		}
	
		elseif ($count==2){
			if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar("Ad After Post 2") ) :
	
			endif;
		}
		else {}
	}
	

Share this post


Link to post
Share on other sites
Simon

yea, thats bad php try this: `register_sidebar( array(` `'name' => 'after_post1',` `'before_widget' => '

',` `'after_widget' => '
',` `'before_title' => '

',` `'after_title' => '

',` `) );` `register_sidebar( array(` `'name' => 'after_post2',` `'before_widget' => '
',` `'after_widget' => '
',` `'before_title' => '

',` `'after_title' => '

',` `) );` `add_action('pagelines_loop_post_end', 'ad_space_after_posts');` `function ad_space_after_posts(){` `global $count;` `if ($count === 1 ) {` `dynamic_sidebar( 'after_post1' ) );` `} else {` `if ( $count === 2 ) {` `dynamic_sidebar( 'after_post2' ) );` `}` `}` `}`

Share this post


Link to post
Share on other sites
barroncuadro

Thanks for the reply Simon. Not sure it's quite there yet. I'm not seeing my test widget that I set up. Also I had to kill the closing parens after dynamic_sidebar, so:

dynamic_sidebar( 'after_post1' )
instead of
dynamic_sidebar( 'after_post1' ) )
the second closed parens broke the site. Also, should there be three equal signs in the count?
$count === 1 

Thanks again for checking into this.

Share this post


Link to post
Share on other sites
Simon

sorry i missed the closing parens == is equal === is identical

Share this post


Link to post
Share on other sites
barroncuadro

So just for clarification, is this correct? I'm still not seeing the result:

		register_sidebar( array(
			'name' => 'after_post1',
			'before_widget' => '<div class="adSpace adPost1">',
			'after_widget' => '</div>',
			'before_title' => '<h2>',
			'after_title' => '</h2>',
		) );
	
		register_sidebar( array(
			'name' => 'after_post2',
			'before_widget' => '<div class="adSpace adPost2">',
			'after_widget' => '</div>',
			'before_title' => '<h2>',
			'after_title' => '</h2>',
		) );
	
		add_action('pagelines_loop_post_end', 'ad_space_after_posts');
		function ad_space_after_posts(){
			global $count;
			if ($count === 1 ) {
				dynamic_sidebar( 'after_post1' );
			} else {
			if ( $count === 2 ) {
				dynamic_sidebar( 'after_post2' );
			}
		}
	}
	

It looks correct. Perhaps I'm missing something?

Share this post


Link to post
Share on other sites
catrina

For the hook you're looking for, you can try the pagelines_after_theloop hook.


Please read the docs before posting. Please do not private message me unless I ask you to.

Designer | Catrina Dulay

Founder | Catrina and Mouse

Share this post


Link to post
Share on other sites
barroncuadro

Hi Catrina, I tried this hook and I'm not getting the result I want. Actually I'm not getting anything at all. Here is the php I'm using:

	register_sidebar( array(
			'name' => 'Ad After Post 1',
			'before_widget' => '<div class="adSpace adPost1">',
			'after_widget' => '</div>',
			'before_title' => '<h2>',
			'after_title' => '</h2>',
		) );
	
		register_sidebar( array(
			'name' => 'Ad After Post 2',
			'before_widget' => '<div class="adSpace adPost2">',
			'after_widget' => '</div>',
			'before_title' => '<h2>',
			'after_title' => '</h2>',
		) );
	
		add_action('pagelines_after_theloop', 'ad_space_after_posts');
		function ad_space_after_posts(){
			global $count;
			if ($count === 1 ) {
				dynamic_sidebar( 'after_post1' );
			} else {
			if ( $count === 2 ) {
				dynamic_sidebar( 'after_post2' );
			}
		}
	} 

Here is the page where the ads should show up (right after the first and second post boxes): http://bit.ly/eYv9XA

Share this post


Link to post
Share on other sites
cmunns

This hook is the closest you'll get: pagelines_loop_post_end You'd have to change the css a touch if you want a different effect. Also, you do have ads actually placed in the widgets correct?

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  

×