Dragonfly CMS v9 ⇒ CPG-BB (forum) :: Archives ⇒ Adsense after first post in forums :: Archived ⇒ Community Forums ⇒ CPG Dragonfly™ CMS
Forum Index Modules & Blocks CPG-BB (forum) ⇒ Archives

Archived ⇒ Adsense after first post in forums


I am attempting to make my google adsense ad appear after the first post in a thread. I have attempted to install a mod to the viewtopic.php file but it appears to not work with the cpg nuke version.

Here are the instructions I tried.

#-----[ OPEN ]------------------------------------------
#
viewtopic.php

#
#-----[ FIND ]------------------------------------------
#
$row_color = ( !($i % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($i % 2) ) ? $theme['td_class1'] : $theme['td_class2'];

#
#-----[ REPLACE WITH ]------------------------------------------
#
$row_color = ( !($num % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($num % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
$num ++;

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

#
#-----[ AFTER, ADD ]------------------------------------------
#
if($i == $ad_after)
{
$row_color = ( !($num % 2) ) ? $theme['td_color1'] : $theme['td_color2'];
$row_class = ( !($num % 2) ) ? $theme['td_class1'] : $theme['td_class2'];
$num ++;

$mini_post_url = append_sid('viewtopic.' . $phpEx . '?' . POST_POST_URL . '=' . $postrow[$i]['post_id']) . '#ad';
$template->assign_block_vars('postrow', array(
'ROW_COLOR' => '#' . $row_color,
'ROW_CLASS' => $row_class,
'POST_DATE' => $post_date,
'POST_SUBJECT' => 'Advertisement',
'MINI_POST_IMG' => $mini_post_img,
'POSTER_NAME' => 'Google',
'POSTER_RANK' => 'Sponsor',
'POSTER_AVATAR' => '<img src="images/google_avatar.gif" alt=""/>',
'MESSAGE' => '<div align=&quot;center&quot;>YOUR ADSENSE CODE HERE</div>',
'L_MINI_POST_ALT' => $mini_post_alt,
'U_MINI_POST' => $mini_post_url,
'U_POST_ID' => 'ad')
);
}

#
#-----[ SAVE/CLOSE ALL FILES ]

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
OS Linux /PHP Version 4.3.11/ CPG Version 9.0.6.1


I don't know the mod (I think you should post a link), but I do something similar with categories ( arrse.co.uk/cpgn2/Forums.html - google ads in some places) and it's quite easy to do with some very simple code.

This is from /modules/Forums/index.php and you would need to do something similar in /modules/Forums/viewtopic.php to set a flag after the first loop through the mysql results:
if ($cat_id == 2 || $cat_id == 13 || $cat_id == 5) { $showGoogle = TRUE; }
then output this to the template by adding a variable to the template variable list, in my case in the same file:
$template->assign_block_vars($cattpl, array( 'S_IS_CAT' => TRUE, 'CAT_ID' => $cat_id, 'CAT_SHOW_GOOGLE' => $showGoogle, 'CAT_DESC' => $category_rows[$i]['cat_title'],

Now go to your template file. Yours would be /yourTheme/includes/templates/forums/viewtopic_body.html and make the theme show the google code if that flag is set:

<!-- IF forumrow.CAT_SHOW_GOOGLE --> <tr> <td class="row1"></td> <td class="row1" colspan="4" align="left"> <div style="position: relative; width: 200px; height: 90px;"> <div style="position: absolute;"> <script type="text/javascript"><!-- google_ad_client = "pub-1565181133397583"; google_ad_width = 728; google_ad_height = 90; google_ad_format = "728x90_as"; google_ad_type = "text"; //2007-01-10: ARRSE Search Results google_ad_channel = "0172694273"; google_color_border = "EFEFEF"; google_color_bg = "EFEFEF"; google_color_link = "000000"; google_color_text = "336600"; google_color_url = "000000"; //--></script> <script type="text/javascript" src="http://pagead2.googlesyndication.com/pagead/show_ads.js"> </script> </div></div> </td> </tr> <!-- ENDIF -->

So actually quite simple to do from scratch. Hope that helps.

Olive Net
British Army
Royal Navy
Military Clothing and Equipment - This Tribe

Server specs (Server OS / Apache / MySQL / PHP / DragonflyCMS):
Slackware 12 / CentOS, PHP 5.6, MySQL 5, Apache 2

All times are UTC