WordPress.org

Ready to get started?Download WordPress

Forums

Easy way to add a banner between every X-number of posts? (6 posts)

  1. jbickers
    Member
    Posted 8 years ago #

    Hi all, does anyone know an easy way to insert non-database content - specifically, a banner or adsense ad - between every 2nd or 3rd post?

    Best,
    James

  2. Mark (podz)
    Support Maven
    Posted 8 years ago #

    http://wordpress.org/support/topic/12685?replies=30#post-202508

    That works to place such content, just add more numbers / use more variables. Does it look okay ?

  3. jbickers
    Member
    Posted 8 years ago #

    Hey podz,

    Thank you! Works great. But do you know a way to make it recurring? i.e. rather than just having the code show up after the 4th post, make it show up after EVERY 4th post?

    Thanks again!
    James

  4. Mark (podz)
    Support Maven
    Posted 8 years ago #

    How many posts per page ... ?
    If you had 16 posts/page then you'll need 4 ads ?
    4-5
    8-9
    12-13
    16-base

    So - not knowing any code and going with a kludgey solution - I'd use more variables:

    <?php
    $postnum = 1;
    $showadsense1 = 4;
    $showadsense2 = 8;
    $showadsense3 = 12;
    $showadsense4 = 16;
    ?>

    then have a
    <?php if ($postnum == $showadsense1)
    OR if ($postnum == $showadsense2)
    OR if ($postnum == $showadsense3)
    OR if ($postnum == $showadsense4)

    and the rest of the code.
    There is probably a much more elegant way of doing this and hopefully someone will help out :)

  5. jbickers
    Member
    Posted 8 years ago #

    I've found a way to make it work - by resetting $postnum to 0 within the loop - but I think it's now an adsense problem, because it only displays correctly the first time, and leaves blank space each subsequent time. Does adsense code want to be unique? It's my first time dealing with them ...

  6. Mark (podz)
    Support Maven
    Posted 8 years ago #

    Adsense is 3 blocks per page ?
    I'm no adsense expert though so I'll have to leave that issue to someone who does use them....

Topic Closed

This topic has been closed to new replies.

About this Topic