This tutorial will explain how to insert ads (like Google AdSense) after the first post in a thread. This is a great way to put ads on your site since it's not too intrusive, and it forces users to see the ads. The only thing you need is the eXtreme Styles MOD for phpBB and a text editor like Wordpad (included with Windows) or a free editor like Notepad++. (You need the XS MOD so that you can put PHP code in your template files. Once you have your advertisement code ready (either login to your account to get the code or ask the company for support), you will need to edit templates/your template name here/viewtopic_body.tpl . (Please note that these instructions are optimized for subSilver so you may need to tweak the HTML code for your own template.)
Here are the instructions in the MOD install format.
- Code: Select all
#
#-----[ OPEN ]------------------------------------------
#
templates/subSilver/viewtopic_body.tpl
#
#-----[ FIND ]------------------------------------------
#
<!-- BEGIN postrow -->
#
#-----[ BEFORE, ADD ]------------------------------------------
#
<?php
$post_number = 0;
?>
#
#-----[ AFTER, ADD ]------------------------------------------
#
# Note: add this after the FIND command above.
#
<?php
$post_number++;
?>
#
#-----[ FIND ]------------------------------------------
#
<!-- END postrow -->
#
#-----[ BEFORE, ADD ]------------------------------------------
#
<?php
if ( $post_number === 1 )
{
?>
<tr>
<td width="150" align="left" valign="top" class="row1"><span class="name"><strong>Sponsor</strong></span></td>
<td class="row1" width="100%" height="28" valign="top">
<br />
<div align="center">
Your ad code goes here.
</div>
</td>
</tr>
<tr>
<td class="row1" width="150" align="left" valign="middle"><span class="nav"><a href="#top" class="nav">{L_BACK_TO_TOP}</a></span></td>
<td class="row1" width="100%" height="28" valign="bottom" nowrap="nowrap"> </td>
</tr>
<tr>
<td class="spaceRow" colspan="2" height="1"><img src="templates/subSilver/images/spacer.gif" alt="" width="1" height="1" /></td>
</tr>
<?php
}
?>
#
#-----[ SAVE/CLOSE ALL FILES ]------------------------------------------
#
# EoM
Just replace Your ad code goes here. above with the ad code provided by your company. Now you will have ads after the first post!
FAQs:
Q. Can I display ads for certain forums only?
A. Yes! Just grab the forum ID number (i.e. when you click on a forum, look for the number after f= in the URL in your browser's address bar). Once you have the ID number, change this line:
- Code: Select all
<?php
if ( $post_number === 1 )
{
?>
to this:
- Code: Select all
<?php
global $forum_id;
$included_forums = array(1, 2, 3);
if ( $post_number === 1 && in_array($forum_id, $included_forums) )
{
?>
Change the 1, 2, 3 to the forum ID numbers that you want to show ads within. Separate each forum ID with a comma.
Q. Can I NOT show ads in certain forums?
A. Yes. This is similar to the above. Get the forum ID number then change this line:
- Code: Select all
<?php
if ( $post_number === 1 )
{
?>
to this:
- Code: Select all
<?php
global $forum_id;
$excluded_forums = array(4, 5, 6);
if ( $post_number === 1 && !in_array($forum_id, $excluded_forums) )
{
?>
Replace 4, 5, 6 with the forum ID numbers that you don't want to show ads in. Separate each forum ID with a comma.
Q. Can I show ads to guests only?
A. Yes. Change this line:
- Code: Select all
<?php
if ( $post_number === 1 )
{
?>
to this:
- Code: Select all
<?php
global $userdata;
if ( $post_number === 1 && !$userdata['session_logged_in'] )
{
?>
Please feel to PM me if you think of any more FAQs or changes to add.
Enjoy!


