• Resolved mrtumnas

    (@mrtumnas)


    My site- https://www.growinggroceries.com currently has only one sidebar ad. I’d like to put image ads in between the posts like they do on https://www.venturebeat.com , for instance. The only way I could figure to do this was to put the code from Google after the
    <?php if (have_posts()) : while (have_posts()) : the_post(); ?> section of the Main Index Template. It worked, but it put an ad after every post, and since that exceeded my ad limit, it wouldn’t show the sidebar ads.

    How can I put ads inbetween only the first one or two posts?

    Thanks- james

Viewing 7 replies - 1 through 7 (of 7 total)
  • One way to do it would be to put a counter in the loop

    <?php
     $i = 0;
    if (have_posts()) : while (have_posts()) : the_post();
    $i++;
    
    [ ... post code here ... ]
    
    if ($i <= 2) {
       [  Google ad code here ]
    } ?>

    That will only print the ad code for the 1st and 2nd post.

    You will probably need to add some additional PHP opening and closing tags once you have inserted the post and Google code

    Thread Starter mrtumnas

    (@mrtumnas)

    Cool, I give that a try tonight and let you know how it works!

    Thread Starter mrtumnas

    (@mrtumnas)

    Okay, using that code made my page not load.

    Do I put the same Google code in both spaces where you say to insert code? I’m pretty new to this whole messing around with code thing. Where exactly do I put the code you gave me?

    Thanks so much!

    Thread Starter mrtumnas

    (@mrtumnas)

    *bump*

    <?php $i = 0;
    if (have_posts()) : while (have_posts()) : the_post();
    $i++; ?>
     POST CODE GOES HERE
    <?php if ($i <= 2) { ?>
     AD CODE HERE
    <?php } ?>

    You just need to open and close the PHP in a few places, as stvwlf said…

    Thread Starter mrtumnas

    (@mrtumnas)

    Thanks, that fixed it, guys. You rock

    mrtummas,
    could you provide a link to your site? I would like to see how you solved the matter, since I have been wondering about the same myself.
    Best regards
    Erico

Viewing 7 replies - 1 through 7 (of 7 total)
  • The topic ‘Ad Boxes Between Posts’ is closed to new replies.