News:

Want to get involved in developing SMF, then why not lend a hand on our github!

Main Menu

Adding adsense after first and last post

Started by Owdy, May 22, 2005, 03:30:44 PM

Previous topic - Next topic

Owdy

I try to put them after first and last post. I got it work, but if theres only one post, it looks silly (2 ads). How can i ad ads after last post, but only if there more than one post?

Current code:

// 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>';
if ($message['id'] == $context['first_message'])
echo '<tr><td class="titlebg"  style="border: 1px solid gray" align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-69056456924584105438";
google_alternate_ad_url = "http://www.example.com/google5.html";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel ="9676543456431073";
google_color_border = "0C40A0";
google_color_bg = "0C40A0";
google_color_link = "FFFFFF";
google_color_url = "FFFFCC";
google_color_text = "FFFFFF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td></tr>'; }
echo '
<tr><td style="padding: 0 0 1px 0;"></td></tr><tr><td class="titlebg"  style="border: 1px solid gray" align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-690345435345284105438";
google_alternate_ad_url = "http://www.example/google5.html";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel ="9676534541073";
google_color_border = "0C40A0";
google_color_bg = "0C40A0";
google_color_link = "FFFFFF";
google_color_url = "FFFFCC";
google_color_text = "FFFFFF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td></tr>
</table>
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

[Unknown]

Use $context['num_replies'] - if it is 0, don't show one of the ads.

-[Unknown]

Owdy

Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

[Unknown]

Find:

if ($message['id'] == $context['first_message'])

Replace:

if ($message['id'] == $context['first_message'] && $context['num_replies'] > 1)

-[Unknown]

Owdy

Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Owdy

#5
It work allmost perfect. If theres 1 reply, google ad is after last post, not first. I wanted to be after first post.

Current code

';
if ($message['id'] == $context['first_message'] && $context['num_replies'] > 1)
echo '<tr><td class="titlebg"  style="border: 1px solid gray" align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-605438";
google_alternate_ad_url = "http://www.example.net/google5.html";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel ="9676541073";
google_color_border = "0C40A0";
google_color_bg = "0C40A0";
google_color_link = "FFFFFF";
google_color_url = "FFFFCC";
google_color_text = "FFFFFF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td></tr>'; }
echo '
<tr><td style="padding: 0 0 1px 0;"></td></tr><tr><td class="titlebg"  style="border: 1px solid gray" align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-84105438";
google_alternate_ad_url = "http://www.example.net/google5.html";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel ="9676541073";
google_color_border = "0C40A0";
google_color_bg = "0C40A0";
google_color_link = "FFFFFF";
google_color_url = "FFFFCC";
google_color_text = "FFFFFF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td></tr>


Is there $context['last_message'] or similar?
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Thantos

';
if ($message['
id'] == $context['first_message'])
echo '
<tr><td class="titlebg"  style="border: 1px solid gray" align="center">
<
script type="text/javascript"><!--
google_ad_client "pub-605438";
google_alternate_ad_url "http://www.example.net/google5.html";
google_ad_width 468;
google_ad_height 60;
google_ad_format "468x60_as";
google_ad_type "text";
google_ad_channel ="9676541073";
google_color_border "0C40A0";
google_color_bg "0C40A0";
google_color_link "FFFFFF";
google_color_url "FFFFCC";
google_color_text "FFFFFF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</
script>
</
td></tr>'; }
if ( $context['
num_replies'] > 1 )
echo '
<tr><td style="padding: 0 0 1px 0;"></td></tr><tr><td class="titlebg"  style="border: 1px solid gray" align="center">
<
script type="text/javascript"><!--
google_ad_client "pub-84105438";
google_alternate_ad_url "http://www.example.net/google5.html";
google_ad_width 468;
google_ad_height 60;
google_ad_format "468x60_as";
google_ad_type "text";
google_ad_channel ="9676541073";
google_color_border "0C40A0";
google_color_bg "0C40A0";
google_color_link "FFFFFF";
google_color_url "FFFFCC";
google_color_text "FFFFFF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</
script>
</
td></tr>';


or something like that :)  Basically you put a condition before the second adsense to determine if you should show it or not

Owdy

Thanks MIke! It works like charm. I ow you 1!  :)
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Owdy

#8
:( it only works in first page of topic. If page 2 etc has only one post, there are 2 ads after each other again.

Current code:

// 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>';
if ($message['id'] == $context['first_message'])
echo '<tr><td class="titlebg"  style="border: 1px solid gray" align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-605438";
google_alternate_ad_url = "http://www.example.net/google5.html";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel ="9676541073";
google_color_border = "0C40A0";
google_color_bg = "0C40A0";
google_color_link = "FFFFFF";
google_color_url = "FFFFCC";
google_color_text = "FFFFFF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td></tr><tr><td style="padding: 0 0 1px 0;"></td></tr>'; }
if ( $context['num_replies'] > 1 )
echo '
<tr><td class="titlebg"  style="border: 1px solid gray" align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-6904105438";
google_alternate_ad_url = "http://www.example.net/google5.html";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text";
google_ad_channel ="9676541073";
google_color_border = "0C40A0";
google_color_bg = "0C40A0";
google_color_link = "FFFFFF";
google_color_url = "FFFFCC";
google_color_text = "FFFFFF";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td></tr>';
echo '
</table>
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Thantos

Ok you'll need to use modulas ( % ) by the number of posts per page.  Let me see if I can find that variable

Thantos

Ok try this
if ( $context['num_replies'] % $modSettings['defaultMaxTopics'] > )

Owdy

Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

Thantos

yeah I just realized I gave the wrong index

Thantos

Ok this is what I did
Find:
while ($message = $context['get_message']())

Add Before:
$numPosts = 0;

Find the closing } for the while loop
Add before that
$numPosts++;

Change your outside if statement to:
if ( $numPosts > 2 )

Owdy

Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

tulie

 :D thanks for the code

could you kindly update the new code... i mean the whole thing as Owdy
posted before...
Thanks  :)
you guys are doing a great job... keep it up.

Zenigata



tulie

#18
Quote from: MikeMill on May 26, 2005, 02:27:38 PM
Ok this is what I did
Find:
while ($message = $context['get_message']())

Add Before:
$numPosts = 0;

Find the closing } for the while loop
Add before that
$numPosts++;

Change your outside if statement to:
if ( $numPosts > 2 )

which out side statement?? :-[
where should i use -
Change your outside if statement to:
if ( $numPosts > 2 )
part?


Owdy

Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

shishira

Quote from: J. S. on June 21, 2005, 09:20:17 AM
Here is my Display.template.php code:

http://www.artdust.ro/test/Display.template.php.txt

Do not forgot to backup your  Display.template.php

Demo:  http://forum.lovesms.ro


sorry file not found anybody with the complete code ???
It always takes longer than you expect, even when you take into account Hofstadter's Law.

http://shiroid.com
http://bangaloreforums.com


legolas

Hi,
I used the displayed.template.php provided by J.S which displays the ads in the 2nd and last post. However, the 2nd ad always displays Russian ads (mostly from adzone.ro). has anyone encountered this when using the displayed.template.php provided by J.S?? BTW my website is not russian.

Owdy

That has nothing to do with template. Use google-ad filter to remove that advertiser. Put 'adzone.ro' to filter list.
Former Lead Support Specialist

Tarvitsetko apua SMF foorumisi kanssa? Otan työtehtäviä vastaan, lue:http://www.simplemachines.org/community/index.php?topic=375918.0

yellow1912

So am I allowed to put google ads on my SMF forum?
My SMF forum ^^
An Ecommerce site I help to build

thetzfreak

Well, I really need to do this, but I have another template, not the default, and I don't have that default.template.php file. All I have in my theme folder is index.php, template.index.php, boardindex.template.php, and themes.template.php. I can't seem to find the correct place anywhere =\

J. S.

Hello.

please edit Display.template.php.
Find there the AdSense code and edit this:

google_ad_client = "xxxx";
replace xxxx with your ad client ID.
second, find this line:
google_alternate_ad_url = "xxxxx";
replace that url wit your alternate add url. If you don`t know what is that, or you don`t have one, please delete that line.

Good luck!

J. S.

Owdy: read below :)
yellow1912: Yes. You may put Google Ads on a SMF forum, however, read the google policy before doing that.
thetzfreak: When you ask for help please provide a URL where we can see what is happening. If you don`t have a Display.template.php file in your theme folder, then the default one will be used (by SMF).

jennypretty

#29
Can you please look at my code? why does the google ad does not show?
It showed after the first post but not on the last one.
Please help...
big thanks...

      // 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>';


if ($message['id'] == $context['first_message'])
echo '<tr><td class="titlebg"  style="border: 1px solid gray" align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-710";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "2D5893";
google_color_bg = "99AACC";
google_color_link = "000000";
google_color_url = "000099";
google_color_text = "003366";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td></tr>'; }
if ( $context['num_replies'] > 1 )
echo '
<tr><td style="padding: 0 0 1px 0;"></td></tr><tr><td class="titlebg"  style="border: 1px solid gray" align="center">
<script type="text/javascript"><!--
google_ad_client = "pub-710";
google_ad_width = 468;
google_ad_height = 60;
google_ad_format = "468x60_as";
google_ad_type = "text_image";
google_ad_channel ="";
google_color_border = "2D5893";
google_color_bg = "99AACC";
google_color_link = "000000";
google_color_url = "000099";
google_color_text = "003366";
//--></script>
<script type="text/javascript"
  src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
</td></tr>';


   echo '
</table>


dejiman

Hi thanks for all your effort . But i have tried to down load various mod form my SMF 1.1.4  eg global header and footer mod. and adsense Mod etc. But they are not just implementing after i have installed it. Please what can i do because i am what to add bidvertiser adsense code on my Forum and also include chat to my forum. Please help me.
IS YOUR DESTINY ELECETED?

Let's know here

ELECTED DESTINIES

Advertisement: