Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: aamjad2001 on September 06, 2011, 05:45:53 PM

Title: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: aamjad2001 on September 06, 2011, 05:45:53 PM
Now you can have a small, rectangular adsense ad appear within and directly beneath the content of the first post in each thread  specially in the core theme.

You can try this approach:
Find in Display.template.php:

<div class="inner" id="msg_', $message['id'], '"', '>', $message['body'], '</div>


Replace the above with:

<div class="inner" id="msg_', $message['id'], '"', '>';
                 if ($message['id'] == $context['first_message'])
      echo '
                        <div style="float:right; width:270px;">
                        <script type="text/javascript"><!--
                        google_ad_client = "pub-xxxxxxxxxxxxxxx";
                        /* 250x250, created 9/07/11 bforum text */
                        google_ad_slot = "xxxxxxxxxxxx";
                        google_ad_width = 250;
                        google_ad_height = 250;
                        //-->
                        </script>
                        <script type="text/javascript"
                        src="http://pagead2.googlesyndication.com/pagead/show_ads.js">
                        </script></div>';
      echo '   
               ', $message['body'], '</div>


You can see the demo here:
http://www.baqaians.com/bforum/general-physician-desk/myths-about-the-menstrual-periods/


Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: wilowterra on November 04, 2011, 02:32:17 PM
 ;D ;D ;D ;D ;D ;D thanks
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: glennk on April 13, 2012, 02:01:27 PM
is this possible for the bigger banners ? I want to put the large adsense banner in the first post only ??
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: NanoSector on April 13, 2012, 02:55:39 PM
@glennk: Yes, that should be possible :)

Also, I don't want to ruin anyone's experience, but this can also be done with Ad Management Mod (http://custom.simplemachines.org/mods/index.php?mod=255), AFAIK. That's a bit simpler for most users, but if you just want it there without installing big mods you can indeed use this :)
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: matricrsult on April 24, 2012, 03:21:25 AM
Hmmm great
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: fifacluborg on May 02, 2012, 08:38:35 AM
@aamjad2001 - Thank you so much for this tutorial... really useful! :)
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: chimbocool on May 09, 2012, 05:00:33 PM
i use Ad Management Mod before i don't like and the ads appear at the top of the post not in the post

and @aamjad2001 - Thank you so much for this tutorial... really useful! 

-------------------------------------

dead4ever.com

Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: ApplianceJunk on May 09, 2012, 05:32:33 PM
Nice tip.

I started using http://www.smfhacks.com/ad-seller-pro.php some time ago.
It lets you create custom ad locations in the template.

It has also help me learn how to manually edit templates too.
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: jonyparks on May 16, 2012, 12:38:25 PM
Thanks a lot for this tutorial.We will be benefited more.
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: PSPguru on January 05, 2013, 06:10:23 AM
I would be very satisfied with the free mod for adsense, thank you for the tutorial
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: LebronJamson on January 20, 2013, 02:50:45 PM
This works just fine. But I would like to put the ad between first and second post, not inside the first. How do I do that?

Ad management mod doesn't work for me, it shows ads only at the top and bottom of the page. Only with this code I was able to put the ad into the post. But I need a little tweek. Thanks in advance, guys. (I have SMF 2, default Core theme)
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: dimspace on February 10, 2013, 10:34:07 PM
is it possible to modify this for guests only.

i am gradually switching to ad free forum for members
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: NanoSector on February 11, 2013, 05:30:46 AM
Quote from: dimspace on February 10, 2013, 10:34:07 PM
is it possible to modify this for guests only.

i am gradually switching to ad free forum for members
In the "replace with" code in the first post,

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

With:
if ($message['id'] == $context['first_message'] && $context['user']['is_guest'])
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: dimspace on February 11, 2013, 09:20:34 PM
Quote from: Yoshi2889 on February 11, 2013, 05:30:46 AM
Quote from: dimspace on February 10, 2013, 10:34:07 PM
is it possible to modify this for guests only.

i am gradually switching to ad free forum for members
In the "replace with" code in the first post,

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

With:
if ($message['id'] == $context['first_message'] && $context['user']['is_guest'])

cheers yoshi.

most of my ads i just use simple portal, i dont have many anyway, just two the right in normal mode, or header and footer in mobile mod, but about five months ago i seperated the guest and member ads so i could track each one.

guests are about 70% of my revenue so im not far from having ad free forum for members with the guests funding the server.
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: NanoSector on February 12, 2013, 05:11:49 AM
That's awesome :)

Do keep in mind that if you get less guests you get less income, so you should be prepared for that.
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: labyo on April 07, 2013, 01:34:24 AM
Thanks so much  :D
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: Namning on April 10, 2013, 05:19:37 AM

Thanks for useful info.
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: knightofdoom on April 23, 2013, 02:29:52 AM
Thanks
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: karde on April 23, 2013, 10:59:23 AM
Thank you, this is great way to add ad in thefirst post without a mod.
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: ryan_dwight on May 13, 2013, 05:48:53 AM
how to make this thing work on specific board only?

because the ad management board doesnt work on "Display ads within posts"

or i just dont know how to do it.
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: solewind on May 14, 2013, 10:29:28 AM
Thanks a lot. It does work for my board.
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: archdearz on May 15, 2013, 10:05:44 AM
Thanks  ;)
Title: Re: Adsense within first post of thread in smf 2.0 specially the core theme
Post by: drfun on December 25, 2013, 06:13:48 PM
Quote from: ryan_dwight on May 13, 2013, 05:48:53 AM
how to make this thing work on specific board only?

because the ad management board doesnt work on "Display ads within posts"

or i just dont know how to do it.