Google adsense in PHPBB

Discussions about the phpBB2 Forum. How to get the best from this powerful script.

Moderator: Moderators

Google adsense in PHPBB

Postby ultimatehandyman » Mon Apr 02, 2007 11:29 am

Would it be possible to translate the Google adsense mod that is used on this site ( http://www.phpbb-seo.com/forums/le-foru ... html#11818 ) into English please?

Thanks in advance

chez
ultimatehandyman
PR2
PR2
 
Posts: 250
Joined: Thu Mar 15, 2007 12:55 am

Advertisement

Postby dcz » Thu Apr 19, 2007 9:50 am

All right, so here is the code used on phpBB SEO :

The principle is the following, I am assuming that the best is to only output AdSense for public content, but it's not necessarily the best solution, for example if you run an 100% private forum.
But for forum being mostly public, I do think that the fact the Google AdSense bot can actually browse all pages with adds will help out them to be better targeted.

So it goes like this, open viewtopc.php and find :

Code: Select all
//
// 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++)


Add before :

Code: Select all
// Google AdSense mod www.phpbb-seo.com
$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 www.phpbb-seo.com


Find :

Code: Select all
      'U_POST_ID' => $postrow[$i]['post_id'])
   );

After add :

Code: Select all
// Google AdSense mod www.phpbb-seo.com
   if ( $add_add && $i == $add_after ) {
      $template->assign_block_vars('postrow.adsence', array(
         'ADSENCE_CODE' => $adsence_code)
      );
   }
// Google AdSense mod www.phpbb-seo.com



Find :
Code: Select all
$template->pparse('body');

Before add :
Code: Select all
// Google AdSense mod dcz
if ( $add_add && $add_switch ) {
   $template->assign_block_vars('adsence', array(
      'ADSENCE_CODE' => $adsence_code)
   );
}
// Google AdSense mod dcz



Open viewtopic_body.tpl and find (this for subSilver):

Code: Select all
   <!-- END postrow -->


Replace with :
Code: Select all
   <!-- 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 -->


Comments :

As is, this mod will output an AdSense after the first post, and one more at the bottom of the topic page in case there is another page in the topic.

Playing with options :
Code: Select all
$add_add = ( $userdata['user_id'] != 2 && $forum_topic_data['auth_view'] == 0 ) ? TRUE : FALSE;


This line defines the overall condition to output adds :

Code: Select all
$userdata['user_id'] != 2 &&


This part prevent adds to be outputted for the user id n°2, (usually the founder), so you can, and should, change this to your personal ID.
It is as well possible to prevent adds output fro all admin at once :
Code: Select all
$add_add = ( $userdata['user_level'] !=  ADMIN && $forum_topic_data['auth_view'] == 0 ) ? TRUE : FALSE;


Or even moderators :

Code: Select all
$add_add = ( $userdata['user_level'] !=  ADMIN && $userdata['user_level'] !=  MOD && $forum_topic_data['auth_view'] == 0 ) ? TRUE : FALSE;


Or even all logged users :

Code: Select all
$add_add = ( !$userdata['session_logged_in'] && $forum_topic_data['auth_view'] == 0 ) ? TRUE : FALSE;


For the second adsense :
Code: Select all
$add_switch = (( floor( $start / intval($board_config['posts_per_page']) ) + 1 ) < ceil( $total_replies / intval($board_config['posts_per_page'])) )? TRUE : FALSE;


Here, we check if there is another page in this topic and decide to output the AdSense.
We could for example only check that this topic page has more than n post in it before we add a second ad sense :

Code: Select all
$add_switch = (count($total_posts) >= 10 )? TRUE : FALSE;



First add position :

Code: Select all
$add_after = 0;


To output it after the second post instead of the first one, one could use :

Code: Select all
$add_after = 1;


One could even use something like :
Code: Select all
$add_after = ( count($total_posts) >= 5 ) ? intval( rand (0, ( count($total_posts) - 3 ) ) ) : 0;


To output the first AdSense at a random position between the first and the 4th post tail ;)

In all this you'll obviously have to replace
Code: Select all
full AdSense code


With your real AdSense add code.
This code does not output any alternative adds, will leave the code 100% untouched in case no add is outputted (private forum or admin for example).

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Postby ultimatehandyman » Sat Apr 21, 2007 12:29 pm

Thanks very much for that :wink:

I will take a look at this when I have more time next week :D

Thanks again :wink:
ultimatehandyman
PR2
PR2
 
Posts: 250
Joined: Thu Mar 15, 2007 12:55 am

Postby ultimatehandyman » Mon Apr 23, 2007 4:02 pm

I just tried installing this mod and it did not seem to work and so I installed it again and it dawned on me that it is designed so that the Admin cannot see the ads when logged in :idea:

When I was not logged in the mod worked and leaves adsense after the first post and at the end of the topic :wink:

This is just what I was looking for :D

Thanks again DCZ :wink:
ultimatehandyman
PR2
PR2
 
Posts: 250
Joined: Thu Mar 15, 2007 12:55 am

Postby spy » Mon Apr 23, 2007 10:20 pm

thanks dcz I'll use it in my forum
spy
 
Posts: 38
Joined: Wed Mar 07, 2007 10:34 pm

Postby dcz » Tue Apr 24, 2007 9:26 am

You're welcome :D
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Google adsense in phpbb with Subcategories

Postby aspelsit » Thu Apr 26, 2007 6:48 pm

I tried to use your Google Adsense mod but i failed since I could not get the codes to change in viewtopic.php since I had upgraded my phpbb to Categories hierarchy v2.1. My question is how can I Use this mod in Categories hierarchy v2.1 forum since Iwant my forum to have subcategories and subforums or Is there any other way of using the google adsense mod and still add subcategories and subforums without using Categories hierarchy v2.1 forum Please any one Help coz ineed both sucategories and adsense!!
aspelsit
 
Posts: 1
Joined: Thu Apr 26, 2007 5:14 pm

Postby dcz » Fri Apr 27, 2007 4:07 pm

And welcome :D

If you only want one level of sub forums, like on phpBB SEO, you could use the simple sub forum mod, it's easier to deal with and will as well allow easier migrating to phpBB3.

About CH, the problem is always the same, it's barely not phpBB anymore, more like a fork.

I'll take a look at it when I'll get more time ;)

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Postby tmhung » Mon May 14, 2007 8:53 am

where i can insert my ad code into this mod . Please help me
tmhung
 
Posts: 14
Joined: Sun May 13, 2007 3:48 am

Postby ultimatehandyman » Mon May 14, 2007 9:18 am

You put your adsense code in this section that is in the viewtopic.php-

Code: Select all
// Google AdSense mod www.phpbb-seo.com
$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 www.phpbb-seo.com


Put your adsense code in between the quotes where it says 'full adsense code'

:wink:
ultimatehandyman
PR2
PR2
 
Posts: 250
Joined: Thu Mar 15, 2007 12:55 am

Postby tmhung » Mon May 14, 2007 12:24 pm

i did like you , but it don't work T_T
tmhung
 
Posts: 14
Joined: Sun May 13, 2007 3:48 am

Postby ultimatehandyman » Mon May 14, 2007 12:47 pm

If you edit the files as suggested by dcz above the mod will work :wink:

Trust me, I am no expert and it worked for me.

When the mod is installed you must log out of the forum or you will not see the ads!

The adsense ads do not show up for the site admin by default.

It can be changed though as dcz has described in his post.

I have mine set so that non logged in users can see the ads.
ultimatehandyman
PR2
PR2
 
Posts: 250
Joined: Thu Mar 15, 2007 12:55 am

Postby dcz » Tue May 15, 2007 7:58 am

Well, had you noticed the mod would only output adds in public forum for anybody but the admin (user id = 2) ?

Did you try to browse you forum as guest or regular user ?

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Postby tmhung » Wed May 16, 2007 3:19 am

i saw it but it on the top of page , don't after first post T_T
tmhung
 
Posts: 14
Joined: Sun May 13, 2007 3:48 am

Postby dcz » Wed May 16, 2007 8:33 am

Then, that's probably because you messed up a bit with the template part.

Check the code changes again, they are few, and about templates, the code change concern subSilver, it should not be very different for other styles but still.

++
Useful links :
SEO Forum || SEO Directory || SEO phpBB || Search
____________________

Liens Utiles :
Forum référencement || Annuaire référencement || Référencement phpBB || Recherche
dcz
Admin
Admin
 
Posts: 21219
Joined: Fri Apr 28, 2006 9:03 pm

Next

Return to phpBB2 Forum

 


  • Related topics
    Replies
    Views
    Last post

Who is online

Users browsing this forum: Google Feedfetcher and 1 guest