• I’m trying to figure out a way to have a google ad placed in between my posts. Not every post – maybe every three posts or something… I’ve seen it done on other sites, I just can’t figure out how to get it to work on my site.

    Does anyone know how to place ads in between posts? Thank you in advance for your help!

Viewing 7 replies - 1 through 7 (of 7 total)
  • Thread Starter icydk

    (@icydk)

    As far as I can see – I didn’t see where it shows how to do what I’m asking…

    I want:

    Post 1
    Post 2
    Post 3

    GOOGLE AD

    Post 4
    Post 5
    Post 6

    GOOGLE AD

    Does this make sense to anyone?

    You can also use something like CG-Inbetween to ‘help’ you. All it takes to set up is a one-line insertion into your index.php template file (where you’d want inserted content to show up…). Then via the admin panel you’d create an inbetween at position “3,6,9” (I think that works), and have it include a file (and put your adsense code in a .HTML file).

    You can also do what CG-Inbetween does manually — which is what the tamba example tries to show. CG-Inbetween uses the call to it in order to track the ‘post counter’, and know when to then output things you’ve set up from the admin interface.

    -d

    icydk,

    I think this tutorial might help you. Feel free to contact me if you have any questions.

    Hi icydk

    1. Login to your WordPress administration panel
    2. Select Presentation ->Theme Editor from the navigation menu
    3. On the Theme Editor page, you will see a list of “theme files” to the right of the page. Select the “Main index template” (index.php).
    4. Find the following line
    <?php while (have_posts()) : the_post(); ?>
    5. Above it add the following line
    <?php $count = 1; ?>
    Comments:-$count is the variable and you have to assign a value to that variable. In this case the value is 1.
    6. Find the line <?php endwhile; ?>
    7. Add the following code directly above it (replace AdSense Code with your code)
    <?php if ($count == 1) : ?>
    AdSense Code 1
    <?php elseif ($count == 2) : ?>
    AdSense Code 2
    <?php endif; $count++; ?>

    Comment:-We can count how many times the loop has cycled by adding the block of code above. Remember at the start we added <?php $count = 1; ?>, well above we check $count, if count is 1 we place adsense code 1, if its 2 we place adsense code 2.NOTE : To change which post your Adsense is placed under, simply change the count number, for example: $count == 2 will place the Adsense under post 2
    8. Find the line <?php endwhile; ?>
    9. Below it add the following code:
    <?php if ($count != 2 AND $count != 3 ) : ?>
    Adsense Code 3
    <?php endif; ?>

    Comment:-The adsense will be added after the very last post on the home page because it’s been added after <?php endwhile; ?>It also tells us that if the adove 2 ads are not the last ads than add Google Adsense Code 3 at the end.
    10. Click Save, then go view your site to confirm that the Adsense has been added to the first post listing on your home page. Note – if you want the same thing to show on the category or archive pages then that’s easy. You just need to copy and paste what you ‘ve done to either your archive.php or category.php.

    If you want to see a demo of this then you can visit my site https://www.bloggerholic.com

    Thanks, dopecoder.

    I used your technique, but I added the Adsense code

    <?php if ($count == 1) : ?>
    AdSense Code 1
    <?php elseif ($count == 2) : ?>
    AdSense Code 2
    <?php endif; $count++; ?>

    (using my Adsense code, of course) right above the </div> corresponding to the <div class="entry"> because I wanted my ads to appear right after the “Continue reading this post” links on my front page. However, nothing is showing up. I can’t see why this modification of your technique wouldn’t work properly. Any hints?

    Nevermind. My site just took a while to update. It’s working perfectly.

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Want to add Google Adsense in between posts!’ is closed to new replies.