Home > Programming > Integrating Adsense with PHP BB2

Integrating Adsense with PHP BB2

December 21st, 2008

It is easy to integrate the adsense in the header and the footer. There are plenty of places where you can find materials related to it.

However, people rarely click on the ads in the header and the footer. The best place to place is between the topics in the the forum. I will show you how to modify two files and exactly two files to place adsense. These two files are viewtopc.php and viewtopic_body.tpl

First Open viewtopic.php

Find

//
// Okay, let's do the loop, yeah come on baby let's do the loop
// and it goes like this ...
//
for($i = 0; $i < $total_posts; $i++)

Before this add

// Google AdSense mod
$add_add = ( $userdata['user_id'] != 2 && $forum_topic_data['auth_view'] == 0 ) ? TRUE : FALSE;
$add_switch = (( floor( $start / intval($board_config['posts_per_page']) ) + 1 ) < ceil( $total_replies / intval($board_config['posts_per_page'])) )? TRUE : FALSE;
$add_after = 0;
if ( $add_add ) {
$adsence_code = 'full adsense code';
}
// Google AdSense mod

A note – The ‘full adsense code’ means the complete javascript code. For example

Next Find

'U_POST_ID' => $postrow[$i]['post_id'])
);

After this Add

// Google AdSense mod
if ( $add_add && $i == $add_after ) {
$template->assign_block_vars(‘postrow.adsence’, array(
‘ADSENCE_CODE’ => $adsence_code)
);
}
// Google AdSense mod

Find :

Code:
$template->pparse(‘body’);


Before add :

Code:
// Google AdSense mod
if ( $add_add && $add_switch ) {
$template->assign_block_vars(‘adsence’, array(
‘ADSENCE_CODE’ => $adsence_code)
);
}
// Google AdSense mod

Now save this file.

Next open file viewtopic_body.tpl and find

<!– END postrow –>

Replace it with the following code

<!– BEGIN adsence –>
<tr>
<td width=”100%” align=”center” valign=”top” class=”row1″ colspan=”2″>{postrow.adsence.ADSENCE_CODE}</td>
</tr>
<tr>
<td class=”spaceRow” colspan=”2″ height=”1″><img src=”templates/subSilver/images/spacer.gif” alt=”" width=”1″ height=”1″ /></td>
</tr>
<!– END adsence –>
<!– END postrow –>
<!– BEGIN adsence –>
<tr>
<td width=”100%” align=”center” valign=”top” class=”row1″ colspan=”2″>{adsence.ADSENCE_CODE}</td>
</tr>
<!– END adsence –>

You are done now. Test your phpbb2 again.

Programming

  1. No comments yet.
  1. No trackbacks yet.