Forums

[Plugin: AdSense Manager] How do I insert Ads after 5 posts (in the middle of 10 posts)? (3 posts)

  1. ultramagnus13
    Member
    Posted 2 years ago #

    Hey There:
    Any ideas how I can insert an ad unit between 10 posts... Basically after the 1st 5 posts on a page.

    Like so:
    ------
    blog
    ------
    blog
    ------
    blog
    ------
    blog
    ------
    blog
    ------
    Ad Unit
    ------
    blog
    ------
    blog
    ------
    blog
    ------
    blog
    ------
    blog
    ------

    Thanks!
    Shelby.

  2. pcwriter
    Member
    Posted 2 years ago #

    @shelby

    You can always insert the shortcode in any post you want, like so:
    [ad#name]

    It won't necessarily be between posts, exactly like you want, but at least you can control in which posts you want ads to appear.

    Hope this helps!

  3. Rayland
    Member
    Posted 2 years ago #

    open index.php and look for something like
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?>

    just above that insert the following:

    <?php $postnum = 1; $showad1 = 6; ?>

    then look for the code that calls the title (it's usually just before the_content tag). for example:
    <h2><a title="<?php the_title(); ?>" href="<?php the_permalink() ?>" rel="bookmark"><?php the_title(); ?></a></h2>

    just above that insert the following:

    <?php if ($postnum == $showad1) {adsensem_ad('YOUR_AD_NAME');} ?>

    make sure you replace YOUR_AD_NAME with the name of the ad you want displayed.

    lastly, look for:
    <?php endwhile; else: ?>

    just above that, insert the following:

    <?php $postnum++; ?>

    save index.php open your site and do a hard refresh.. the ad should appear just before the 6th post..

Topic Closed

This topic has been closed to new replies.

About this Topic