Simple Machines Community Forum

SMF Support => SMF 1.1.x Support => Aiheen aloitti: jdougher - heinäkuu 03, 2010, 09:39:48 AP

Otsikko: Add adsense at end of first post - within first post
Kirjoitti: jdougher - heinäkuu 03, 2010, 09:39:48 AP
Where in Display.template.php (or elsewhere) would I insert adsense code so that ads appear at the end of the first post, WITHIN the first post, as in the screen cap below, and what code would I use to precede the adsense code so that ads show up only to guests?

Thanks.

Please don't suggest the ad management mod. It does not address this.
Otsikko: Re: Add adsense at end of first post - within first post
Kirjoitti: mirahalo - heinäkuu 15, 2010, 12:06:29 IP
on your display.template find this:


<div class="post"', $message['can_modify'] ? ' id="msg_' . $message['id'] . '"' : '', '>', $message['body'], '</div>


and replace with this:

<div class="post"', $message['can_modify'] ? ' id="msg_' . $message['id'] . '"' : '', '>', $message['body'], '';
if ($message['counter'] == 0 && $context['user']['is_guest'])
echo 'your ads here';

echo '</div>';



change the "your ads here"  eith the adsense code, remember, simple commas ' within the echo  needs to be escape with \  like this   \'
Otsikko: Re: Add adsense at end of first post - within first post
Kirjoitti: jdougher - heinäkuu 16, 2010, 09:46:06 AP
Did exactly as you said, and the forum blew up. Restored from backup. Any ideas?
Otsikko: Re: Add adsense at end of first post - within first post
Kirjoitti: mirahalo - heinäkuu 16, 2010, 11:58:15 AP
why will blow up?   the most you can have was a syntax error easily fixed but thats all.


can you please attach your display.template of the theme your currently using
Otsikko: Re: Add adsense at end of first post - within first post
Kirjoitti: jdougher - heinäkuu 16, 2010, 12:00:19 IP
Yes, here it is.
Otsikko: Re: Add adsense at end of first post - within first post
Kirjoitti: mirahalo - heinäkuu 16, 2010, 12:13:58 IP
can you also provide your adsense code or your ads code so I can put in there too ;)
Otsikko: Re: Add adsense at end of first post - within first post
Kirjoitti: jdougher - heinäkuu 16, 2010, 01:05:17 IP
Sure, here it is:

<script type="text/javascript"><!--
google_ad_client = "pub-0000000000000000";
/* 250x250, created 7/3/10 */
google_ad_slot = "4655500000";
google_ad_width = 250;
google_ad_height = 250;
//-->
</script>
<script type="text/javascript"
src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
</script>
Otsikko: Re: Add adsense at end of first post - within first post
Kirjoitti: mirahalo - heinäkuu 16, 2010, 01:21:53 IP
ok, use this, if for some reason your forum mark an error, you don't have to restore your hole site again, just tell me and I will check on it.
Otsikko: Re: Add adsense at end of first post - within first post
Kirjoitti: jdougher - heinäkuu 16, 2010, 02:34:43 IP
Thanks, but this breaks the forum. Error message upon viewing thread:

Otsikko: Re: Add adsense at end of first post - within first post
Kirjoitti: Hj Ahmad Rasyid Hj Ismail - elokuu 03, 2010, 11:10:16 AP
Lainaus käyttäjältä: jdougher - heinäkuu 16, 2010, 02:34:43 IP
Thanks, but this breaks the forum. Error message upon viewing thread:
Change:
echo '</div>';


, $message['can_modify'] ? '

to:
echo '</div>', $message['can_modify'] ? '
Otsikko: Re: Add adsense at end of first post - within first post
Kirjoitti: MrMike - kesäkuu 18, 2011, 02:27:05 IP
Just an update to this for SMF 2.0.....

SMF 2.0 uses a var named $is_first_post to make it easy to determine if you're in the first post in a topic. To add Adsense or other ad code to the bottom of the first post, this should work.

In Display.template.php, search for this code:
        // Show the member's signature?
        if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
            echo '
                    <div class="signature" id="msg_', $message['id'], '_signature">', $message['member']['signature'], '</div>';

        echo '
                </div>
            </div>
        </div>';
    }


Replace it with this code:
                // Show the member's signature?
        if (!empty($message['member']['signature']) && empty($options['show_no_signatures']) && $context['signature_enabled'])
            echo '
                    <div class="signature" id="msg_', $message['id'], '_signature">', $message['member']['signature'], '</div>';

        echo '
                </div>';

            if ($is_first_post == 1){
       
                echo '...your Adsense code...';
       
            }

        echo '
            </div>
        </div>';
    }


Hope this helps someone!