1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

Help with adsense code in wordpress

Discussion in 'Blogging' started by craigjarvis, Jul 19, 2010.

  1. craigjarvis

    craigjarvis Registered Member

    Joined:
    Nov 19, 2009
    Messages:
    80
    Likes Received:
    12
    I have a code setup in my index.php to insert my ad into the first post of the page only with this code
    <?php the_content(__('(more...)')); ?>
    <?php if ($count == 1) : ?>
    <script type="text/javascript"><!--
    google_ad_client = "pub-*************";
    /* 300x250, created 7/15/10 */
    google_ad_slot = "5671363641";
    google_ad_width = 300;
    google_ad_height = 250;
    //-->
    </script>
    <script type="text/javascript"
    src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>

    How do I change it to cause ads to be inserted into the first 3 posts?

    Thanks for your help.
     
  2. bhnoob

    bhnoob Newbie

    Joined:
    Jul 12, 2008
    Messages:
    41
    Likes Received:
    9
    It would be a lot easier and more flexible if you used a plugin instead of hard coding your index file. There are lots of free ones available for adsense ad placement. Try this one:

    Code:
    http://wordpress.org/extend/plugins/quick-adsense/
     
    • Thanks Thanks x 1
  3. tomlondon

    tomlondon Junior Member

    Joined:
    Apr 3, 2010
    Messages:
    135
    Likes Received:
    37
    Yeah, just G00gle quick adsense wordpress plugin, pretty self explanatory, you can insert adsense wherever you want (beginning of the post/page, middle, end etc). You can also use widget "Arbitrary text or HTML" to have a nice wide (160x600) skyscraper in your sidebar.
     
    • Thanks Thanks x 1
  4. craigjarvis

    craigjarvis Registered Member

    Joined:
    Nov 19, 2009
    Messages:
    80
    Likes Received:
    12
    I thought about using a plugin, but Ive had them mess up my site code once, and insert someone elses adsense codes into my site once so Id rather code it. Just cant figure out what to change in the code. I copied the code from another site....
     
  5. bhnoob

    bhnoob Newbie

    Joined:
    Jul 12, 2008
    Messages:
    41
    Likes Received:
    9
    What theme and what version of WordPress are you using? Without knowing that, here is what i'd try.

    I have all my WordPress sites set to display the entire post instead of excerpts so I dont have any "more" links .. but from what you posted it looks like they set the index file to search the posts for
    Code:
    <?php the_content(__('(more...)')); ?>
    and just hard coded the adsense block between the end of the excerpt and above the "more" link on the first post with
    Code:
    <?php if ($count == 1) : ?>
    So it seems like you should be able to just re use the same code over twice more changing ($count == 1) to ($count == 2) and ($count == 3) . ( I don't see any point in coding a loop since you are only allowed 3 adsense blocks)

     
  6. craigjarvis

    craigjarvis Registered Member

    Joined:
    Nov 19, 2009
    Messages:
    80
    Likes Received:
    12
    Thanks for the tips. Can you show me how you get the full content and no ecxerps? I use an rss feed from google news.

    BTW im usuing 2.92 I believe, and an iphone 4 theme i found.
     
  7. me8626

    me8626 Registered Member

    Joined:
    Jan 29, 2009
    Messages:
    54
    Likes Received:
    27
    You can use the Easy Adsense Plugin, just search for it on Google, this plugin works great and its very easy to use!