News:

Wondering if this will always be free?  See why free is better.

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'] > 1 )

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?


Advertisement: