WordPress.org

Support

Support » Themes and Templates » Easy way to add a banner between every X-number of posts?

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

  • 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

Viewing 5 replies - 1 through 5 (of 5 total)
  • 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 ?

    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

    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 🙂

    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 …

    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….

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Easy way to add a banner between every X-number of posts?’ is closed to new replies.
Skip to toolbar