manojgupta26

Add Adsense Code On Homepage After Two Post Counts

6 posts in this topic

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

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.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites

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


Share this post


Link to post
Share on other sites

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

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.


Former PageLines Moderator, Food Expert and Raconteur

Share this post


Link to post
Share on other sites

Thanks for being "Harsh"


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

  • Similar Content

    • oseehys
      By oseehys+
      Hello There,
      So i want to use platform 5 and DMS sections on a single page, i am using a child theme with pinspro as my main theme and i activated platform 5, the only problem am having so far is the fixed option, my navbars are not aligning to their default size, and it will be great if platform 5 header and footer section will function, has anyone used this option, how can i make the best use of platform 5 and DMS on a site
      Cheers
    • thirdstonemedia
      By thirdstonemedia+
      I've been fighting with a resolution issue ? Want to use Flick Slider, the site looks great on my monitor but client says she can't see bottom of homes. I believe she's on an old PC using outdated browser/s ... but, she's important to me and I'd like to make this work, on her system. Without asking her adjust her own set-up. 
      I put the Flick Slider inside a container, here ::
      http://becauze.xyz/home-five
      Set the Height of Flick Slider to 50 Base ... I don't know how this works exactly ... there is a Base then a Min ... but, haven't adjusted the Min ::
      http://becauze.xyz/home-four/
      Tried using Splash Up, which presents the same issue (she can only see top of home) and she wants several images to rotate on Home page, so not sure this would work anyway ::
      http://becauze.xyz/
      I have tried going into Layout and making the width narrower, and that does make the site narrower, but the homes still don't display in full, on her system. Help ?

      Here are her screen grabs, both desktop and iPad  (dumped the chalkboard background).

      FInally, she said these look great ::
      http://www.sinclairaia.com/
      http://www.kristihanson.com/
      What am I doing wrong ?? Is there a better way to accomplish making the site look great on any resolution at any size ?
      Joanne
      (Longtime Pagelines-lover.)


    • Suneel
      By Suneel+
      I updated my theme to framework and now can't get rid of this bright blue bar that appears across the top of every page. It says, "A fixed bar that makes it easy to promote important content.", and then a button that says, "Get PageLines".
      I am a novice and need help.
      Thank you!
      Natalie
    • kwaoru
      By kwaoru
      Hi,
       
      I have been using DMS and pagelines.
      I am facing to a huge trouble with the appearance of one of my page on mobile (smart phones) built with pagelines.
      However I haven’t come to any solutions to organise either edit the appearance of mobile view to look neat or deactivate the responsive function. 
      Now it looks totally messy on the phone...
       
      1. Is there any way to edit the appearance of the mobile version (responsive theme)?
      2. Is there any way to deactivate responsive function?
       
      If I could receive support from you to go thorough this process I would be happy to be a pro member. 
       
      Looking forward to hearing from you.
    • kwaoru
      By kwaoru
      Hi,
      I desperately need to deactivate the responsive function on mobile for reasons. It looks so messy with the responsive look on mobile and not navigating or informative at all as it is. 
      I searched for solutions online and tries some of those that I found but nothing worked out. Also I found a previous post on this forum says that this theme pagelines DMS is not meant to be build to deactivate the responsive function... 
      Also tried with widget such as WPtouch to edit the mobile look a little more informative but as I am using "single page" theme on pagelines, the frontpage(main page) never appears on those app.
      Seems like not compatible?
      If there is no way to deactivate responsive function or I'll have to recreate another page just dedicated for a mobile page? or change the theme completely and build a page from scratch?
      I have been searching for this for two days already...
      Could anyone wise and kind out there, please help me?
       
      Thanks,