How to Add Advertisements After the First Post in a Thread

Frequently asked questions about administrating your forum.

Moderator: Moderators

How to Add Advertisements After the First Post in a Thread

Postby pentapenguin on Tue Sep 26, 2006 5:28 am

Hello.

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">&nbsp;</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! :D
User avatar
pentapenguin
Moderator
Moderator
 
Posts: 1466
Joined: Tue Sep 14, 2004 4:15 pm
Location: Georgia, USA

Postby UseLess on Wed Nov 01, 2006 7:42 pm

Greetings,

For MorpheusX users the code to add needs to be changed, this should be obvious from the 'viewtopic_post_<above | left | right | none>.tpl' files, as each post is in a table of it's own with an added header and footer. Therefore adding code meant for 'subSilver', as in adding 'table rows' outside a table will break the HTML and thus the layout of the page.

So you do this;
[code highlight="5,22"]<?php
if ( $post_number === 1 )
{
?>
{TPL_HDR1}<some text in here if you wish>{TPL_HDR2}<table border="0" cellpadding="0" cellspacing="0" width="100%" class="post1">
<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">&nbsp;</td>
</tr>
<tr>
<td class="spaceRow" colspan="2" height="1"><img src="templates/subSilver/images/spacer.gif" alt="" width="1" height="1" /></td>
</tr>
</table>{TPL_FTR}
<?php
}
?>[/code]
Add the highlighted lines.... ;)
Movie Quote:
It's not the years honey, it's the mileage...

I do not provide any install services for phpBB, Mods or Styles.
Please do not pm me for support/scripting help - you won't get any reply. If you have a question then make a post in the appropriate forum.
User avatar
UseLess
Registered User
Registered User
 
Posts: 6220
Joined: Mon Sep 27, 2004 2:14 am
Location: North East, UK


Return to phpBB Administration FAQ

Who is online

Users browsing this forum: No registered users and 1 guest

cron