Jump to content


Photo
- - - - -

Add Adsense Code On Homepage After Two Post Counts

pagelines

Best Answer Simon_P , 15 December 2012 - 04:40 PM

Your code will not work as it is copy and pasted from thesis hook.

 

 

 

 
add_action('pagelines_loop_after_excerpt', 'after_first_post_ad');
function after_first_post_ad($post_count) {
    if (is_home()) {
        global $post_ad_count;
        if ($post_ad_count == 2) { ?>
<!-- GOOGLE AD CODE START HERE -->
<script type="text/javascript"><!--
google_ad_client = "ca-pub-34XXXXXXXXXXXXXXX";
/* Top-Sidebar-300x250*/
google_ad_slot = "4089184913";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googl...ead/show_ads.js">
</script>
<!-- GOOGLE AD CODE ENDS HERE -->
<?php
        }
        $post_ad_count++;
    }
}
Go to the full post


  • Please log in to reply
5 replies to this topic

#1 manojgupta26

manojgupta26

    Super Member

  • Members
  • 144 posts
  • Country: Country Flag

Posted 15 December 2012 - 07:19 AM

I want to add adsense code on homepage after two posts excerpt using th following code. but it is not working at all. I tried using hooks  'pagelines_loop_after_excerpt'. Please help me how can i achieve it. I have installed wordpress 3.5 with latest version of pagelines framework and base theme.
 
 
add_action('pagelines_loop_after_excerpt', 'after_first_post_ad');
function after_first_post_ad($post_count) {
    if (is_home()) {
        if ($post_count == 2) { ?>
<!-- GOOGLE AD CODE START HERE -->
<script type="text/javascript"><!--
google_ad_client = "ca-pub-34XXXXXXXXXXXXXXX";
/* Top-Sidebar-300x250*/
google_ad_slot = "4089184913";
google_ad_width = 300;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="

Please Login or Register to see this Hidden Content

">
</script>
<!-- GOOGLE AD CODE ENDS HERE -->
<?php
        }
    }
}


#2 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 15 December 2012 - 11:45 AM

Manoj,

 

In cases such as this, I'm afraid such a customization takes the help of a Pro because trying to break into the loop can cause harm to your site.  So, I'd refer you to

Please Login or Register to see this Hidden Content

 

On the flip side of that, What I have done in past is to use

Please Login or Register to see this Hidden Content

and the

Please Login or Register to see this Hidden Content

.  This would allow you to emulate the loop using customized shortcode you create yourself and some easy CSS.   Both plugins are free, but have premium versions at CodeCanyon.net.

 

Place Special Recent Posts shortcode on a static homepage for the 1st two posts. You may have to use CSS to resize the thumbnail, but it's very easy to do. 

 

Below it, using the Boxer plugin, which creates content blocks, insert the shortcode for a block-set.    The block set has one box, and it contains the AdSense code.

 

Following this, more shortcode for Special Recent Posts, this one offsetting the post list by 2, and displaying 8 or whatever number you'd like.

 

So, the page would have

  • 2 posts
  • ad
  • 8 posts

 

That seemed to be the layout you were seeking.

 

Note: If you were going to style the ads, such as centering, you can still do so with the content block.  Simply wrap the code in a unique class and use CSS to align the ad as desired. You may also be able to achieve this with the settings of Boxer plugin.



#3 manojgupta26

manojgupta26

    Super Member

  • Members
  • 144 posts
  • Country: Country Flag

Posted 15 December 2012 - 04:06 PM

I don't want to use plugins. Thanks for not providing straight solution.



#4 Simon_P

Simon_P

    Messer

  • Administrators
  • 8388607 posts
  • LocationDevon
  • Framework Version:2.0
  • Country: Country Flag

Posted 15 December 2012 - 04:40 PM   Best Answer

Your code will not work as it is copy and pasted from thesis hook.

 

 

 

Please Login or Register to see this Hidden Content



#5 Rob

Rob

    One Smart Egg

  • Members
  • 13575 posts
  • LocationEast Coast, USA
  • Framework Version:The Latest, of course
  • Country: Country Flag

Posted 15 December 2012 - 05:54 PM

Since you refuse my recommended solution and are using the wrong code to begin with,  perhaps you'll now hire a Pro, as suggested.  We cannot customize your site for you via the forum.  Customizations are done by professional web designers on our team.

 

I tried offering you a viable option, which you rejected.  I'm sorry my solution was unsatisfactory and wish you only the best luck with your project.



#6 manojgupta26

manojgupta26

    Super Member

  • Members
  • 144 posts
  • Country: Country Flag

Posted 31 December 2012 - 02:49 PM

Thanks for being "Harsh"







Also tagged with one or more of these keywords: pagelines