Skip to:
Content
Pages
Categories
Search
Top
Bottom

How to add a script or ads after 1st post of every topics

  • Hi, I want to add google adsense ads to just 1st post of every topic.. What sort of editing is required in topic.php of my theme ???

Viewing 4 replies - 1 through 4 (of 4 total)

  • chrishajer
    Participant

    @chrishajer

    Just add it to the template file. To make it show up after the first post only, you need a counter to see which post you’re looping through. I did something like this:

    <ol id="thread" class="list:post">

    <?php foreach ($posts as $bb_post) : $del_class = post_del_class(); ?>
    <li id="post-<?php post_id(); ?>"<?php alt_class('post', $del_class); ?>>
    <?php bb_post_template(); ?>
    </li>
    <?php if ($adcounter == 0) {
    $adcounter++;
    // <div id="adcode">paste ad code here</div>
    } ?>
    <?php endforeach; ?>

    </ol>

    Basically just add the adcounter check and ad code right after the closing <li> right after the post_template. You’ll have to adjust the particulars for your installation, but this is the basic process.

    I understood the code and I had tried something similar before putting this thread here live but then the topic page fails to load, i don’t know what I m doing wrong ?


    chrishajer
    Participant

    @chrishajer

    You will need someone who can help you debug the code then. Something is out of order.

    You can post your whole topic.php at pastebin and post a link here:

    http://pastebin.com/

    Make sure you let the code stay there longer than one day (default is a month which should be OK)

    @ chrishjaer, here is the link to code on paste bin > http://pastebin.com/m3cb3a4a0 ….. waiting for your reply

Viewing 4 replies - 1 through 4 (of 4 total)
  • You must be logged in to reply to this topic.
Skip to toolbar