Archived

This topic is now archived and is closed to further replies.

  • 0

Add Adsense Code On Homepage After Two Post Counts


Question

Posted · Report post

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"
</script>
<!-- GOOGLE AD CODE ENDS HERE -->
<?php
        }
    }
}

Share this post


Link to post
Share on other sites

5 answers to this question

Posted · Report post

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++;
    }
}

Share this post


Link to post
Share on other sites

Posted · Report post

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 www.pagelines.com/pros

 

On the flip side of that, What I have done in past is to use Special Recent Posts plugin and the WP-Boxer plugin.  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.

Share this post


Link to post
Share on other sites

Posted · Report post

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

Share this post


Link to post
Share on other sites

Posted · Report post

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.

Share this post


Link to post
Share on other sites

Posted · Report post

Thanks for being "Harsh"

Share this post


Link to post
Share on other sites