Viewing 15 replies - 1 through 15 (of 19 total)
  • BEFORE the if ($posts) line, add:
    <?php $postCounter = 0; ?>
    AFTER the if ($posts) line add:
    <?php
    $postCounter++;
    if ($postCount==2) { /* do ad here */ }
    ?>

    -d

    Thread Starter charles

    (@charles)

    David, thanks for your help. It is complaining about an “unexpected ‘<‘ in the line where the google script starts. Here is my modified code:
    <?php $postCounter = 0; ?>
    <?php if ($posts) { foreach ($posts as $post) { start_wp(); ?>
    <?php $postCounter++; if ($postCount==2) (<script type="text/javascript"><!--
    google_ad_client = "pub-6133397951787340";
    google_ad_width = 468;
    google_ad_height = 60;
    google_ad_format = "468x60_as";
    google_ad_channel ="";
    google_color_border = "999999";
    google_color_bg = "FFFFFF";
    google_color_link = "0000FF";
    google_color_url = "008000";
    google_color_text = "000000";
    //--></script>
    <script type="text/javascript"
    src="https://pagead2.googlesyndication.com/pagead/show_ads.js">
    </script>) ?>

    Again, thanks for your help.

    Thread Starter charles

    (@charles)

    hmm… it’s not letting me post my google code in the forum…

    i am getting a parse error saying tat it requires ‘<‘ in line 54.
    abhi.

    this script doesn’t seem to work at all… can anybody provide the correct solution.
    thank you.
    abhi.

    There is a plugin called “Moose Candy” that will allow you to place virtually any content in between posts. You can decide what and where to place this stuff.
    Currently I use it on my own site, at https://blog.nuclearmoose.ca but I’m using it only for text-based quotes. No reason why you couldn’t edit the file and have whatever you like be inserted into the DIV.
    Moose Candy.

    moose candy rocks… i just installed it on my site n it works like a breeze… ??
    abhi.

    Sorry, I assume people have some idea of PHP when they ask for these things! ??
    BEFORE the if ($posts) line, add:

    <?php $postCounter = 0; ?>

    AFTER the if ($posts) line add:

    <?php $postCounter++; if ($postCount==2) { ?>
    .. do HTML/script here ..
    <?php } ?>

    -d

    MooseCandy is pretty neat……yeah baby ??

    I couldn’t get moosecandy to work with code inserted, it was fine with just text though – what should I be doing?

    I tried David’s code:
    <?php $postCounter = 0; ?>

    AFTER the if ($posts) line add:

    <?php $postCounter++; if ($postCount==2) { ?>
    .. do HTML/script here ..
    <?php } ?>

    And it is not giving me errors, but nothing is showing up.
    My site is: https://blog.freedomdown.net/ . Thanks for your help in advance ;).

    – Erik

    Same as Eric. And Moose Candy can’t be found.

    You don’t need to hand-enter code any more. I released my CG-Inbetween plugin to enable easily doing these kinds of things.

    I’ve been busy, and can’t recall if I updated the site to have the latest and greatest code — if you find anything not working, ping me at cgcode at chait dot net, and I’ll get right on it… (my paying work comes first! ?? ).

    -d

    The adsense wordpress plugin allows you to add google ads to whatever posts you want (up to the limit of 3 per page imposed by google).

    Alternatively, the adrotator wordpress plugin allows you to rotate google adsense and other ads within the same space.

    I’ve used both. The adsense adds a quicktag to the post write area, just click to add the code at the end of your posts.

    I use the adrotator on one site for non google ads (though it can be used for google also). For that I added the php ad call function (specified in the plugin instructions) into the post.php file in the theme I’m using. It shows the ads after every post. If you have a front page with 15 posts, only 3 will have google or can have google. This plugin allows you to have 12 additional ads on the page.

    I love them both, and I’m a total non techie — just followed the instructions and used some common sense and trial and error. Both were figured out quickly. No need to mess with code — good grief that would fry me.

    CG-Inbetween was built to insert text/html (i.e., javascript ad code), included file (i.e., htm/php file), or simple php function call output, after specified posts on a page. All you do is add one line of code to your template, the rest is done through an admin interface.

    It’s great for inserting things after say the 3rd, 6th, and 9th posts — or whatever post ID’s you want. Also, the include functionality makes it easy to keep your adsense in an HTML file, in case you want to tweak it, but then ‘attach’ it off of a few post indices.

    It also has the concept of ‘last post’ on the page, good for having a particular ad/file inserted at the end of each page’s worth of posts. It can also go inbetween all posts, good for playing with dividers without constantly touching code.

    Anyway, if people have questions, feel free to ask! ??

    -d

Viewing 15 replies - 1 through 15 (of 19 total)
  • The topic ‘Insert google ad inbetween first and second post’ is closed to new replies.