Forum advice :: How I placed Adsense on my forum.

Started by Niteblade, February 25, 2007, 09:47:21 PM

Previous topic - Next topic

Niteblade

Edit: 06-18-2007: I am re-installing my forum.

[Note]
I'm not "supporting" this modification. I got some help over at Webmasterstalks. Backup your files before you modify them. Please update this code with your adsense ID. All I did was put adsense inside its own <table> after I saw a </table> in the files that I modified.
[/note]

index.template.php -- Puts adsense on every page; useful if you use Tinyportal left and right blocks..


// If we're on a certain board, limit it to this board ;).
elseif (!empty($context['current_board']))
echo '
<input type="hidden" name="brd[', $context['current_board'], ']" value="', $context['current_board'], '" />';

echo '
</form>
</td>
</tr>
</table>';

// Begin Adsense on Index.
echo '
<table width="100%" cellpadding="5" cellspacing="0" style="table-layout: fixed;" class="windowbg">
<tr>
<td valign="top" width="85%" height="100%">
<div style="overflow: auto; width: 100%;" align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2007-02-18: midessa-forum-728x90
google_ad_channel = "8891092745";
google_color_border = "2B2B30";
google_color_bg = "2B2B30";
google_color_link = "FFFFFF";
google_color_text = "D0D0D0";
google_color_url = "F7DDAA";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</td>
</tr>
</table>
';

// End of Adsense on Index.


BoardIndex.template.php -- Puts adsense on Board Index, before Info Center.

// Show the mark all as read button?
if ($settings['show_mark_read'] && !empty($context['categories']))
echo '
<table cellpadding="0" cellspacing="0" border="0" style="position: relative; top: -5px;">
<tr>
', template_button_strip($mark_read_button, 'top'), '
</tr>
</table>';
echo '
</td>
</tr>
</table>';
}

// Adsense before info center.
    echo '
<table width="100%" cellpadding="5" cellspacing="0" style="table-layout: fixed;">
                    <tr>
                        <td valign="top" width="85%" height="100%" class="windowbg2">
<div style="overflow: auto; width: 100%;" align="center" class="windowbg">
<script type="text/javascript"><!--
google_ad_client = "pub-";
google_ad_width = 468;
google_ad_height = 15;
google_ad_format = "468x15_0ads_al";
//2007-02-18: midessa-forum-468x15
google_ad_channel = "8866871717";
google_color_border = "423935";
google_color_bg = "423935";
google_color_link = "D0D0D0";
google_color_text = "000000";
google_color_url = "008000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</td>
</tr>
</table>
<table width="100%" cellpadding="5" cellspacing="0" style="table-layout: fixed;">
                    <tr>
<td valign="top" width="85%" height="100%" class="windowbg">
<br />
<div style="overflow: auto; width: 100%;" align="center" class="windowbg">
<br />
<script type="text/javascript"><!--
google_ad_client = "pub-";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
//2007-02-18: midessa-forum-468x60
google_ad_channel = "8764535480";
google_color_border = "2B2B30";
google_color_bg = "2B2B30";
google_color_link = "FFFFFF";
google_color_text = "D0D0D0";
google_color_url = "F7DDAA";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br><br />
</div>
<br />
</td>
</tr>
</table>';
// End Adsense before info center.

// Here's where the "Info Center" starts...
echo '<br />
<div class="tborder" ', $context['browser']['needs_size_fix'] && !$context['browser']['is_ie6'] ? 'style="width: 100%;"' : '', '>
<div class="catbg" style="padding: 6px; vertical-align: middle; text-align: center; ">
<a href="#" onclick="shrinkHeaderIC(!current_header_ic); return false;"><img id="upshrink_ic" src="', $settings['images_url'], '/', empty($options['collapse_header_ic']) ? 'collapse.gif' : 'expand.gif', '" alt="*" title="', $txt['upshrink_description'], '" style="margin-right: 2ex;" align="right" /></a>
', $txt[685], '
</div>
<div id="upshrinkHeaderIC"', empty($options['collapse_header_ic']) ? '' : ' style="display: none;"', '>
<table border="0" width="100%" cellspacing="1" cellpadding="4" class="bordercolor">';


Display.template.php -- Puts adsense after EVERY first post.

// Show the member's signature?
if (!empty($message['member']['signature']) && empty($options['show_no_signatures']))
echo '
<hr width="100%" size="1" class="hrcolor" />
<div class="signature">', $message['member']['signature'], '</div>';

echo '
</td>
</tr>
</table>
</td></tr>
</table>
</td></tr>';

// Adsense after first post.
if ($message['id'] == $context['first_message'])
{
    echo '
        <tr>
<td style="padding: 0px 1px 0 1px;">
<table width="100%" cellpadding="5" cellspacing="0" style="table-layout: fixed;">
                    <tr>
                        <td valign="top" width="85%" height="100%" class="windowbg2">
<div style="overflow: auto; width: 100%;" align="center" class="windowbg">
<script type="text/javascript"><!--
google_ad_client = "pub-";
google_ad_width = 468;
google_ad_height = 15;
google_ad_format = "468x15_0ads_al";
//2007-02-18: midessa-forum-468x15
google_ad_channel = "8866871717";
google_color_border = "423935";
google_color_bg = "423935";
google_color_link = "D0D0D0";
google_color_text = "000000";
google_color_url = "008000";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</div>
</td>
</tr>
</table>
<table width="100%" cellpadding="5" cellspacing="0" style="table-layout: fixed;">
                    <tr>
<td valign="top" width="85%" height="100%" class="windowbg">
<br />
<div style="overflow: auto; width: 100%;" align="center" class="windowbg">
<script type="text/javascript"><!--
google_ad_client = "pub-";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
//2007-02-18: midessa-forum-468x60
google_ad_channel = "8764535480";
google_color_border = "2B2B30";
google_color_bg = "2B2B30";
google_color_link = "FFFFFF";
google_color_text = "D0D0D0";
google_color_url = "F7DDAA";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
<br><br/>
</div>
<br />
</td>
</tr>
</table>
</td>
</tr>';
}
// End Adsense after first post.


affiliate blog

Muldoon

nite0859,

Thank you so much! As I have to head off to bed soon, I'll hopefully be able to tackle this tomorrow. woot! Can't wait to get started.

Muldoon

Niteblade

#2
I also posted information about how to integrate Amazon searching into posts.
http://www.simplemachines.org/community/index.php?topic=154105.0

Demo : here.
Edit: 06-18-2007
affiliate blog

Roph

I'll just share something I've done - placed ads after the first post of a topic and only made them visible to guests.

in display.template.php,

// Show the member's signature?
if (!empty($message['member']['signature']) && empty($options['show_no_signatures']))
echo '
<hr width="100%" size="1" class="hrcolor" />
<div class="signature">', $message['member']['signature'], '</div>';

echo '
</td>
</tr>
</table>
</td></tr>
</table>
</td></tr>';
//Ads

if ($message['id'] == $context['first_message'] && $context['user']['is_guest'])
{
echo '
<tr><td style="padding: 1px 1px 0 1px;">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr><td class="windowbg">
<div align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-7302574677795924";
google_alternate_color = "EEEEEE";
google_ad_width = 728;
google_ad_height = 90;
google_ad_format = "728x90_as";
google_ad_type = "text_image";
//2006-12-12: RMRK
google_ad_channel = "8337678587";
google_color_border = "EEEEEE";
google_color_bg = "EEEEEE";
google_color_link = "7880A8";
google_color_text = "000000";
google_color_url = "7880A8";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script><br>Registered users do not see advertisements. Please consider <a href="http://rmrk.net/index.php?action=register;" title="Register">registering</a>!
</div>
</td></tr></table></td></tr>';
}
}



echo '

<tr><td style="padding: 0 0 1px 0;"></td></tr>

</table>

<a name="lastPost"></a>';

echo '
<tr><td style="padding: 0 0 1px 0;"></td></tr>
</table>
<a name="lastPost"></a>';

// As before, build the custom button right.


of course change the ad code and put in your own details :)

I also showed a small notice to guests mentioning that they don't see them if they sign up. It seems to work pretty well at getting more people to register :)

HoTmetal


sniderz

This is a great code addition. I have added it to my forums over at www.sniderz.com and have pushed it to the right. My question is, is there anyway to make it as its own post? What I mean it you could create a user called Google that posts ads after the first post on all forums.

If this is not available could I ad a avatar to the left sie of this code to at least make it look like it was a poster?

Roph

I'm not sure if that'd go down too well with google's policies. They might see it as deceptive, trying to make it look like a user's post in order to get clicks. But either way, it shouldn't be that hard. I'll see what I can do.

Personally, I wouldn't try that on my own forum though.

sniderz

#7
Quote from: Silverline on March 14, 2007, 07:59:57 AM
I'm not sure if that'd go down too well with google's policies. They might see it as deceptive, trying to make it look like a user's post in order to get clicks. But either way, it shouldn't be that hard. I'll see what I can do.

Personally, I wouldn't try that on my own forum though.

I appreciate the help !!

Also phpbb, ip board and many others do it like that , that is why I am asking.

Thanks again for the help !!!

http://www.got-heroes.com/The-list-is-unfair-t1088.html is where I saw it last.

Harro


Niteblade

Quote from: Harro on March 14, 2007, 10:17:33 AM
Great post.
Should deserve a sticky actually.

The Admin of webmaster's Talks deserves 100% credit. I took his idea and modified it a little bit. Hopefully more people will take advantage of his knowledge and skill, since it does indeed exceed mine.
affiliate blog

usama07

hey thnxs for that!!
I was really looking for that...
hxxp:sign-profit.com/cgi-bin/ck.pl?id=141165 [nonactive]

crud3w4re

www.anoniche.com
Join my site ...please :)

sniderz

I actually am using the ad mod and it works great for 1 set of ads. As in I can't use after the first post for both adsense and auctionads etc.  Its a great mod but should allow for more occurrences of different ad companies.

Harro

Quote from: crud3w4re on March 15, 2007, 02:22:48 PM
Here's a better solution: Use the admod. ;)
When doing it manually you never have to look at compatability isues, new versions,...

Roph

I originally just wrote my own directly into my template because as an admin I couldn't stop myself seeing the ads, as I automatically have all privelages (so it includes being able to see the ads). I only want to show ads to guests. Though now I hear the ad mod can do that =o

sniderz

From what I have seen yes it can show only to guests. My ads are making me to much money now to take them away from members. I think once the community grows a bit more I will start taking them out.
Need to pay hosting fees :-)

Niteblade

#16
* nite0859 freaks that his post is a sticky.

Looks like I'm going to provide a little more detail for other positions as well. However, I do recommend that one looks at the code reference points found inside the installation XML for the ad mangement mod.

In a nut shell it boils down to this. When editing particular file, search for </table> .  Chances are, if you place adsense in another <table> right after </table> you'll be fine; this is how I am experimenting.

When doing a <table> you can use <td=align="center" valign="middle" class="windowbg"> in order to cut that table in half in order to display two adsense scripts side by side.

Example


<table>
<td align="center" valign="middle" class=windowbg">

Adsense CODE here.

</td>
<td align="center" valign="middle" class=windowbg">

Adsense CODE here too.

</td>
</table>



And if you really want to get funky ::


<table>
<td align="center" valign="middle" class=windowbg">
<div class="windowbg2">

Adsense CODE here.
</div>
</td>
<td align="center" valign="middle" class=windowbg">
<div class="windowbg2">

Adsense CODE here too.

</div>
</td>
</table>


Remember, also backup your original files BEFORE experimenting.

Putting adsense on top of a graphical banner for better design

  • If there are any photoshop people that read this thread, then I recommend that you check out http://adclustr.com/ in order to set your adsense INSIDE a graphical table for an even more unique custom design for adsense.
  • SHARE YOUR DESIGNS WITH YOUR SMF COMMUNITY!!  ;D

Imagine putting a 160x600 adsense banner, that uses a white background (#FFFFFF) in side this graphic table to create a nice shade effect.


Please, don't let this thread degenerate into a "You click on my ads and I'll click on yours" type thing. It's unethical, you'll get banned from Google, and you'll stir the anger from many other members on here. Be cool, be creative.

affiliate blog

Niteblade

#17
Original post :: here.

In order to encourage Guests to register for an account on your forum, you can choose to display certain messages and advertisements to them. Registered members can see a different message or advertisement in the same location, or you can choose to omit the message or advertisement entirely for registered members.

Always make backups of your files before attempting any coding modification.

The file to be edited largely depends upon where you desire to have the advertisement and/or message shown.


  • /Themes/default/index.template.php is rendered on every page.
  • /Themes/default/Display.template.php is rendered when examining a particular post.
  • /Themes/default/MessageIndex.template.php is rendered when examining the total number of threads inside a particular board.
  • /Themes/default/BoardIndex.template.php is rendered on the inital page of the forum; it is the file that renders all of the boards, recent posts, and the information center at the bottom.

The key here is to make a particular piece of coding "conditional". This means that the code is executed only after certain conditions are met.

Remember, I always put "more" code in so that you can find reference points. Also, do not simply cut and paste this code; this is custom code for my forum and it will not work on yours. You have to edit the URL of the image you desire to use, and the URL of your forum.

Quote
In the code below, my actual code begins where ::
// This message is shown to guests. This message will disappear upon registration.

index.template.php

// Show a random news item? (or you could pick one from news_lines...)
if (!empty($settings['enable_news']))
echo '
<td width="90%" class="titlebg2">
<span class="smalltext"><b>', $txt[102], '</b>: ', $context['random_news_line'], '</span>
</td>';
echo '
<td class="titlebg2" align="right" nowrap="nowrap" valign="top">
<form action="', $scripturl, '?action=search2" method="post" accept-charset="', $context['character_set'], '" style="margin: 0;">
<a href="', $scripturl, '?action=search;advanced"><img src="'.$settings['images_url'].'/filter.gif" align="middle" style="margin: 0 1ex;" alt="" /></a>
<input type="text" name="search" value="" style="width: 190px;" />&nbsp;
<input type="submit" name="submit" value="', $txt[182], '" style="width: 11ex;" />
<input type="hidden" name="advanced" value="0" />';

// Search within current topic?
if (!empty($context['current_topic']))
echo '
<input type="hidden" name="topic" value="', $context['current_topic'], '" />';

// If we're on a certain board, limit it to this board ;).
elseif (!empty($context['current_board']))
echo '
<input type="hidden" name="brd[', $context['current_board'], ']" value="', $context['current_board'], '" />';

echo '
</form>
</td>
</tr>
</table>';

// This message is shown to guests. This message will disappear upon registration.
if ($context['user']['is_guest'])
echo '
<table width="100%" cellpadding="5" cellspacing="0" style="table-layout: fixed;">
<td width="65px" align="center" valign="middle" class="windowbg3">
<a href="http://forum.midessa.net/index.php?action=register"><img src="http://XXX.XXX.XXX/Themes/default/images/XXX.png" alt="Register to remove banner" title="Register an account to close this banner" />
</a>
</td>
<td valign="middle" class="windowbg3">
<font size="3" color="#D0D0D0"><b>You are browsing this forum as a guest. Please <a href="http://forum.midessa.net/index.php?action=register">register</a> for an account or <a href="http://forum.midessa.net/index.php?action=login">login</a> to remove this message.</b></font>
</td>
</table>';

// This message is shown to users with a low post count < 5. This message will disappear after 5 posts.
global $user_info;
if (($context['user']['is_logged']) && ($user_info['posts'] < 5 ))
echo '
<table width="100%" cellpadding="5" cellspacing="0" style="table-layout: fixed;">
<td width="65px" align="center" valign="middle" class="windowbg3">
<a href="http://forum.midessa.net/introductions-b11.0/"><img src="http://XXXX.XXXX.XXX/Themes/default/images/XXX.gif" alt="Your post count is too low." title="Please contribute 5 messages to our community" />
</a>
</td>
<td valign="middle" class="windowbg3">
<font size="3" color="#E0E0FF"><b>Please contribute 5 thoughtful posts in order to remove this message.</b></font>
</td>
</table>';


The conditional statement that identifies guests is
  • if ($context['user']['is_guest'])

The conditional statement used to identify registered members who have a low post count
  • global $user_info;
    if (($context['user']['is_logged']) && ($user_info['posts'] < 5 ))

In a similar vein, you can choose to display certain advertisements to guests while showing other, different, advertisements to members.

Quote
In the below example, my actual code begins where ::
// Guests will always see a 468x60 Graphical Banner right about the search form.

index.template.php

// display the time
echo '
<td class="titlebg2" height="32" align="right">
<span class="smalltext">' , $context['current_time'], '</span>';

// this is the upshrink button for the user info section
echo '
<a href="#" onclick="shrinkHeader(!current_header); return false;"><img id="upshrink" src="', $settings['images_url'], '/', empty($options['collapse_header']) ? 'upshrink.gif' : 'upshrink2.gif', '" alt="*" title="', $txt['upshrink_description'], '" align="bottom" style="margin: 0 1ex;" /></a>
</td>
</tr>
<tr id="upshrinkHeader"', empty($options['collapse_header']) ? '' : ' style="display: none;"', '>
<td valign="top" colspan="2">
<table width="100%" class="bordercolor" cellpadding="8" cellspacing="1" border="0" style="margin-top: 1px;">
<tr>';

if (!empty($context['user']['avatar']))
echo '
<td class="windowbg" valign="middle">', $context['user']['avatar']['image'], '</td>';

echo '
<td colspan="2" width="100%" valign="top" class="windowbg2"><span class="middletext">';

// If the user is logged in, display stuff like their name, new messages, etc.
if ($context['user']['is_logged'])
{
echo '
<a href="', $scripturl, '?action=unread">', $txt['unread_since_visit'], '</a> <br />
<a href="', $scripturl, '?action=unreadreplies">', $txt['show_unread_replies'], '</a><br />';



}
// Otherwise they're a guest - send them a lovely greeting...
else
echo $txt['welcome_guest'];

// Guests will always see a 468x60 Graphical Banner right above the search form.
if ($context['user']['is_guest'])
echo '
<td valign="middle" align="right" class="windowbg2">
<script type="text/javascript"><!--
google_ad_client = "pub-";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "image";
//2007-03-17: midessa-forum-468x60
google_ad_channel = "8764535480";
google_color_border = "323935";
google_color_bg = "323935";
google_color_link = "FFFFCC";
google_color_text = "D0D0D0";
google_color_url = "FFFFFF";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td>';

// However, registered members will see a 234x60 Text Banner above the search form.
else
echo '
<td valign="middle" align="right" class="windowbg2">
<script type="text/javascript"><!--
google_ad_client = "pub-";
google_ad_width = 234;
google_ad_height = 60;
google_ad_format = "234x60_as";
google_ad_type = "text";
//2007-03-15: midessa-forum-234x60
google_ad_channel = "9422463529";
google_color_border = "323935";
google_color_bg = "323935";
google_color_link = "99C9FF";
google_color_text = "D0D0D0";
google_color_url = "FFFFFF";
//-->
</script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td>';
affiliate blog

qd-race

I want to manual mod to other theme. What files should I edit?
http://www.qd-race.com |  http://www.replica2u.com  |  http://www.steamyx.net

Niteblade

Quote from: qd-race on April 01, 2007, 01:25:11 AM
I want to manual mod to other theme. What files should I edit?

Check out the very first post ...
affiliate blog

Advertisement: