Skip to:

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


    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(); ?>
    <?php if ($adcounter == 0) {
    // <div id="adcode">paste ad code here</div>
    } ?>
    <?php endforeach; ?>


    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 ?



    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:

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