Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Anthony` on April 22, 2011, 11:27:52 AM

Title: [SMF Tip] Various Ad Placements
Post by: Anthony` on April 22, 2011, 11:27:52 AM
This quick SMF tip will show you where you can put various ads on your page (using Google's Adsense for example) using template edits. This is just if you would like to add a quick ad or two on your pages, if you want full control and automation for ads then I suggest you use a modification. This tutorial was made for SMF 2.0.
 
Under the navigation menu
 
This will display the ad right under your navigation menu. In your theme's index.template.php, find,
Code: [Select]
// Show the menu here, according to the menu sub template.
 template_menu();
 
 echo '
  <br class="clear" />
 </div></div>';

Above the two div tags, two new tags will be made to move the ad code down a line and a div tag with style properties to center it. Here is an example of what it should look like when done,
Code: [Select]
echo '
  <br class="clear" />
<br />
<div style="text-align: center;">
PLACE YOUR AD CODE HERE
</div>
 </div></div>';

Under the Who's Online
 
From here, your ad will be displayed under the Who's Online section of your forum. In your theme's index.template.php, find,
Code: [Select]
echo '
  </div>
 </div></div>';
 
 // Show the "Powered by" and "Valid" logos, as well as the copyright. Remember, the copyright must be somewhere!

And replace that with,
Code: [Select]
echo '
<br />
<div style="text-align: center;">
PLACE YOUR AD CODE HERE
</div>
  </div>
 </div></div>';
 
 // Show the "Powered by" and "Valid" logos, as well as the copyright. Remember, the copyright must be somewhere!

Remember to place your ad code in there.
 
Above the first post
 
This will display your ad above the original poster's message in a topic. In your theme's Display.template.php, find,
Code: [Select]
  echo '
        <div class="inner" id="msg_', $message['id'], '"', '>', $message['body'], '</div>
       </div>';

Replace that with,
Code: [Select]
  echo '
        <div class="inner" id="msg_', $message['id'], '"', '>' . ($message['counter'] == 0 ? '<div style="text-align: left;">
YOUR AD CODE HERE
</div>
<br />' : '') . '', $message['body'], '</div>
       </div>';

This code determines if the message is the first one in the topic, it will display the ad above the message. If you want this to be displayed to guests only, in the above code change,
Code: [Select]
$message['counter'] == 0 ?To,
Code: [Select]
$message['counter'] == 0 && $context['user']['is_guest'] ?
To the right of the first post
 
This will display your ad floating to the right of the first message of the original topic. Follow the instructions above, except change,
Code: [Select]
<div style="text-align: left;">To,
Code: [Select]
<div style="float: right;">
 
That concludes this small SMF tip. Some mods of interest:
Global Headers and Footers - You can use this mod to display the ads only in the header and footer.
http://custom.simplemachines.org/mods/index.php?mod=351 (http://custom.simplemachines.org/mods/index.php?mod=351)
 
Ad Management - Modification for displaying these ads in specified locations.
http://custom.simplemachines.org/mods/index.php?mod=255 (http://custom.simplemachines.org/mods/index.php?mod=255)
 
Thanks for reading!
Title: Re: [SMF Tip] Various Ad Placements
Post by: kat on April 22, 2011, 11:54:46 AM
As this is a tip, I've moved it to...


er...


Tips!
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on April 22, 2011, 11:55:50 AM
As this is a tip, I've moved it to...


er...


Tips!

Woohoo!  O:)
Title: Re: [SMF Tip] Various Ad Placements
Post by: NanoSector on April 22, 2011, 11:56:59 AM
/me comes to mind to simplify this...
Title: Re: [SMF Tip] Various Ad Placements
Post by: kat on April 22, 2011, 11:58:20 AM
Woohoo!  O:)

(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fwww.katzy.dsl.pipex.com%2FSmileys%2Fa063.gif&hash=6a3977fba4d8c43f153e88ba29696362)
Title: Re: [SMF Tip] Various Ad Placements
Post by: Masterd on April 22, 2011, 03:31:41 PM
This is a really nice tip. :D
Title: Re: [SMF Tip] Various Ad Placements
Post by: NHWD on April 23, 2011, 02:19:00 AM
/me comes to mind to simplify this...
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on April 23, 2011, 10:26:44 AM
This is just if you would like to add a quick ad or two, if you want full control and automation for ads then I suggest you use a modification.
Title: Re: [SMF Tip] Various Ad Placements
Post by: NanoSector on April 23, 2011, 02:12:50 PM
This is just if you would like to add a quick ad or two, if you want full control and automation for ads then I suggest you use a modification.
/me comes to mind to simplify this...

:P

That mod handles large and tiny needs for ads.
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on April 23, 2011, 02:17:54 PM
This is just if you would like to add a quick ad or two, if you want full control and automation for ads then I suggest you use a modification.
/me comes to mind to simplify this...

:P

That mod handles large and tiny needs for ads.

Personally, I wouldnt bother with a mod if im adding an ad or two. Like what if the mod had errors anyway, you would have to fix them just to display the one or two ads you want. :p
Title: Re: [SMF Tip] Various Ad Placements
Post by: NanoSector on April 23, 2011, 02:19:05 PM
This is just if you would like to add a quick ad or two, if you want full control and automation for ads then I suggest you use a modification.
/me comes to mind to simplify this...

:P

That mod handles large and tiny needs for ads.

Personally, I wouldnt bother with a mod if im adding an ad or two. Like what if the mod had errors anyway, you would have to fix them just to display the one or two ads you want. :p
I'd rather be lazy and use that mod for it; it's not there just for the looks of it (can't say that it looks bad, however) :P
Title: Re: [SMF Tip] Various Ad Placements
Post by: 008Rohit on April 24, 2011, 10:53:35 AM
as vbgamer's Ad Management mod doesnt completely work with CORE theme I am hoping for code from you for placing ads after the last post of a topic. :)
Title: Re: [SMF Tip] Various Ad Placements
Post by: NanoSector on April 24, 2011, 11:03:14 AM
as vbgamer's Ad Management mod doesnt completely work with CORE theme I am hoping for code from you for placing ads after the last post of a topic. :)
Because Core is based from SMF 1.1.x and Curve is from 2.0...
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on April 24, 2011, 11:16:41 AM
as vbgamer's Ad Management mod doesnt completely work with CORE theme I am hoping for code from you for placing ads after the last post of a topic. :)

If you need it somewhere and cant find it (which is most probable since I based this on SMF 2.0) I am willing to help find it for you.  ;)
Title: Re: [SMF Tip] Various Ad Placements
Post by: Arantor on April 24, 2011, 11:27:27 AM
as vbgamer's Ad Management mod doesnt completely work with CORE theme I am hoping for code from you for placing ads after the last post of a topic. :)
Because Core is based from SMF 1.1.x and Curve is from 2.0...

It apparently doesn't work properly actually on the Core theme, either the 1.1.x or 2.0 versions... and by all accounts doesn't uninstall properly either.
Title: Re: [SMF Tip] Various Ad Placements
Post by: Hj Ahmad Rasyid Hj Ismail on April 24, 2011, 11:28:19 AM
Though I like using mods, I like having a tip and trick like this, just in case I need to do things manually later on. Thanks for the tips and tricks PE.
Title: Re: [SMF Tip] Various Ad Placements
Post by: Sandra Khairul Riz on April 24, 2011, 02:44:40 PM
Hi, I really like these coding tips.  Please how can I display ad after the first post in smf 2.0. Thanks
Title: Re: [SMF Tip] Various Ad Placements
Post by: NanoSector on April 24, 2011, 02:45:19 PM
Hi, I really like these coding tips.  Please how can I display ad after the first post in smf 2.0. Thanks
With Ad Management Mod. And in this topic if you read further then your nose is :P
Title: Re: [SMF Tip] Various Ad Placements
Post by: Rs Bots Pro on April 26, 2011, 05:21:20 PM
Hi, I really like these coding tips.  Please how can I display ad after the first post in smf 2.0. Thanks
With Ad Management Mod. And in this topic if you read further then your nose is :P
none of the mods work with the majority of themes for RC4 & 5 and the ad management mod doesnt work with the default theme curve on RC5 =/ =[
Title: Re: [SMF Tip] Various Ad Placements
Post by: skotinos on May 13, 2011, 10:21:14 PM
Hi, I really like these coding tips.  Please how can I display ad after the first post in smf 2.0. Thanks
With Ad Management Mod. And in this topic if you read further then your nose is :P
none of the mods work with the majority of themes for RC4 & 5 and the ad management mod doesnt work with the default theme curve on RC5 =/ =[

yes, really do not work
Title: Re: [SMF Tip] Various Ad Placements
Post by: abidejaz4u on July 17, 2011, 08:25:56 AM
i want to put ads in the post???
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on July 17, 2011, 11:07:04 AM
i want to put ads in the post???

Look at the last heading.
Title: Re: [SMF Tip] Various Ad Placements
Post by: DragonLady on August 02, 2011, 01:00:15 AM
Hi everyone! :D

I'm trying to add a row of small banners to Curve theme, but everytime I try I give myself parse errors.  Can anyone give me a step-by-step like the one in the OP for putting them along the bottom under "who's online"?

I'd appreciate it very, very much!

Thanks in advance,

DL

edited to say 'curve' not 'core'
Title: Re: [SMF Tip] Various Ad Placements
Post by: DragonLady on August 02, 2011, 01:11:11 AM
Ah...got it!  Thank-you!!!!! :D
Title: Re: [SMF Tip] Various Ad Placements
Post by: Mick. on August 13, 2011, 11:22:54 AM
Very cool tip.
The ad mod has an annoying copyright in the footer.  This tip is the way to go.
Title: Re: [SMF Tip] Various Ad Placements
Post by: moguns on August 14, 2011, 12:16:40 PM
If I wanted to ad this:
Quote
<div align="center"><a href="http://membership.nrahq.org/default.asp?campaignid=XR024435"><img alt="JOIN_NRA07" src="http://www.mogunowners.net/JOIN_NRA07.gif" style="border: 0px solid; margin: 0px;"></a><a href="http://membership.nrahq.org/default.asp?campaignid=XR024435"><font color="#ff0000" face="'Arial Black', Helvetica, sans-serif" size="3">10$ off discount for full year NRA memberships through MOGO!</font><font color="#ff0000">&nbsp;</font></a></div>

What do I do? I put it in and I get a error.

Any help would be great
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on August 14, 2011, 12:53:54 PM
I need to know what sort of error you get.
Title: Re: [SMF Tip] Various Ad Placements
Post by: moguns on August 14, 2011, 01:12:48 PM
I get this:

Quote
Parse error: syntax error, unexpected T_STRING in .../Themes/default/Display.template.php on line 506
when I add this.
Quote
echo '
        <div class="inner" id="msg_', $message['id'], '"', '>' . ($message['counter'] == 0 ? '<div style="text-align: left;">
<div align="center"><a href="http://membership.nrahq.org/default.asp?campaignid=XR024435"><img alt="JOIN_NRA07" src="http://www.mogunowners.net/JOIN_NRA07.gif" style="border: 0px solid; margin: 0px;"></a><a href="http://membership.nrahq.org/default.asp?campaignid=XR024435"><font color="#ff0000" face="'Arial Black', Helvetica, sans-serif" size="3">10$ off discount for full year NRA memberships through MOGO!</font><font color="#ff0000">&nbsp;</font></a></div>
</div>
<br />' : '') . '', $message['body'], '</div>


Thank you for you help
Title: Re: [SMF Tip] Various Ad Placements
Post by: Mick. on August 14, 2011, 01:45:22 PM
Looks like you forgot to add the '; after the last div..... and it may also need an echo' to start the rest of the default code.
Title: Re: [SMF Tip] Various Ad Placements
Post by: moguns on August 14, 2011, 02:42:29 PM
I have it showing. But it highlights the hole message as a link. Is that right?

Thanks
Title: Re: [SMF Tip] Various Ad Placements
Post by: die2mrw007 on September 17, 2011, 11:00:34 AM
I need to have adsense leaderboard layout under the top navigation menu

But there is no such code in my theme index_template.php file

Here is what I found a similar code with template_menu() function:

Quote
echo '
         </div>
      </div>
   </div>
   <div id="toolbar">
      <div class="wrapper">
         ', template_menu(), '
      </div>
   </div>
   <div id="main_body">
      <div class="wrapper">
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on September 17, 2011, 12:10:31 PM
Try placing it under the call to template_menu().
Title: Re: [SMF Tip] Various Ad Placements
Post by: die2mrw007 on September 17, 2011, 12:25:05 PM
Try placing it under the call to template_menu().

I tried and it worked..but not at the desired location..
And sorry, I actually want it not straight under the navigation menu...

I have attached a screenshot...this is where I want the ad to be present...(currently using a mod)
And I dont wish to use any mod for this.

(https://lh3.googleusercontent.com/-henm6o5lPCU/TnTKZD_WnrI/AAAAAAAABMk/kVHW6bkjb2A/s640/ads.JPG)
Title: Re: [SMF Tip] Various Ad Placements
Post by: die2mrw007 on September 17, 2011, 12:25:56 PM
I am unable to attach any file here :(
Why so ??
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on September 17, 2011, 12:42:45 PM
Then it would probably be under where <div class="wrapper"> is.
Title: Re: [SMF Tip] Various Ad Placements
Post by: bigletterj on October 25, 2011, 01:37:33 PM
I just installed the google ads successfully but the
Code: [Select]
<br> doesn't work after the Google ad code. Even the
Code: [Select]
<br style="clear:both;" /> is not working. So now, it is overlapping the content on the forum. Please see http://forums.kshownow.asia/index.php to see how it looks like now.
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on October 25, 2011, 04:31:48 PM
I just installed the google ads successfully but the
Code: [Select]
<br> doesn't work after the Google ad code. Even the
Code: [Select]
<br style="clear:both;" /> is not working. So now, it is overlapping the content on the forum. Please see http://forums.kshownow.asia/index.php to see how it looks like now.

I cant seem to find an issue with both IE9 and FF4. Is this happening at a certain area, what browser were you viewing it on?
Title: Re: [SMF Tip] Various Ad Placements
Post by: Bulldog091 on November 19, 2011, 02:09:43 PM
Thanks for the tip, works like a Swiss watch  :D
Title: Re: [SMF Tip] Various Ad Placements
Post by: ayex on November 22, 2011, 02:35:31 AM
Please where in display.template.php will I edit to show this in message body but below the posts not above. I want the ad to be immediately after the post like its part of the post not in another line like ad management mode did it. I want the add to be part of the message content and not segmented or seperated.
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on November 22, 2011, 04:54:03 PM
Please where in display.template.php will I edit to show this in message body but below the posts not above. I want the ad to be immediately after the post like its part of the post not in another line like ad management mode did it. I want the add to be part of the message content and not segmented or seperated.

Does this go above the last edit text? Can I have a picture example?
Title: Re: [SMF Tip] Various Ad Placements
Post by: ayex on November 23, 2011, 12:29:43 PM
This below is exactly what i want to achiev. i want to add my addthis code to display below every first posts.
This is my addthis code
Code: [Select]
<!-- AddThis Button BEGIN -->
<div class="addthis_toolbox addthis_default_style ">
<a class="addthis_button_preferred_1"></a>
<a class="addthis_button_preferred_2"></a>
<a class="addthis_button_preferred_3"></a>
<a class="addthis_button_preferred_4"></a>
<a class="addthis_button_compact"></a>
<a class="addthis_counter addthis_bubble_style"></a>
</div>
<script type="text/javascript" src="http://s7.addthis.com/js/250/addthis_widget.js#pubid=xa-4ebe356d72f8f3b3"></script>
<!-- AddThis Button END -->
Please where do i place my addthis code for it to appear inside the post like below. I want the share button to be part of the messge body and not divided by a line away from the message body like the ad management mod did it.
(https://www.simplemachines.org/community/proxy.php?request=http%3A%2F%2Fpictureshoster.com%2Ffiles%2F2qmlfk77dq997qdpfvc.png&hash=29d3e143cd42c74c7087e8b5f3a6ba2e)
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on November 23, 2011, 04:43:51 PM
Okay, lets give this a shot then. In Display.template.php,
Code: (After) [Select]
<div class="inner" id="msg_', $message['id'], '"', '>', $message['body'], '</div>
Code: (Add) [Select]
' . ($message['counter'] == 0 && $context['user']['is_guest'] ? '<br /><div style="text-align: left;">
   YOUR AD CODE HERE
</div>' : '') . '

All you have to do is replace YOUR AD CODE HERE with the code snippet you provided.
Therefore, the entire code modified should look something like,
Code: [Select]
echo '
<div class="inner" id="msg_', $message['id'], '"', '>', $message['body'], '</div>
                                ' . ($message['counter'] == 0 && $context['user']['is_guest'] ? '<br /><div style="text-align: left;">
                                    YOUR AD CODE HERE
                                </div>' : '') . '
</div>';
Title: Re: [SMF Tip] Various Ad Placements
Post by: ayex on November 24, 2011, 01:09:52 PM
Thanks it worked on my web version but it didnt work on my wap2. i want the codes to be showing on wap2 after inside the post too. Please how do i do that?, thanks for the help

I read that if someone want to display anything both in web and wap2, then sources/display.php is to be edit?. Please Project Evolution, where will i edit in my sources/display.php to be able to place addthis button below the first post both in web and wap2. Thanks alot for your time
Title: Re: [SMF Tip] Various Ad Placements
Post by: Anthony` on November 25, 2011, 04:38:01 PM
Thanks it worked on my web version but it didnt work on my wap2. i want the codes to be showing on wap2 after inside the post too. Please how do i do that?, thanks for the help

I read that if someone want to display anything both in web and wap2, then sources/display.php is to be edit?. Please Project Evolution, where will i edit in my sources/display.php to be able to place addthis button below the first post both in web and wap2. Thanks alot for your time

If you go to Wireless.template.php, and find the template_wap_display function, this is responsible for what is rendered to your WAP-enabled device.

If you modify something along the lines of,
Code: [Select]
echo '
<p><u>', $message['member']['name'], '</u>:', (!$message['approved'] ? '&nbsp;<em>(' . $txt['awaiting_approval'] . ')</em>' : ''), '<br /></p>
<p>', $message['body'], '<br /><br /></p>';

You can get this working. I just dont know how it would work if you added the div and script tags in there, so give it a shot.
Title: Re: [SMF Tip] Various Ad Placements
Post by: swaggaderby on October 17, 2014, 02:42:46 PM
what about adding ads inside all post....?
Title: Re: [SMF Tip] Various Ad Placements
Post by: Hj Ahmad Rasyid Hj Ismail on October 18, 2014, 12:35:54 AM
Code: [Select]
  echo '
        <div class="inner" id="msg_', $message['id'], '"', '>', $message['body'], '</div>
       </div>';

Replace that with,
Code: [Select]
  echo '
        <div class="inner" id="msg_', $message['id'], '"', '>' . ($message['counter'] == 0 ? '<div style="text-align: left;">
YOUR AD CODE HERE
</div>
<br />' : '') . '', $message['body'], '</div>
       </div>';

Change the replacement code to:
Code: [Select]
  echo '
        <div class="inner" id="msg_', $message['id'], '"', '>
YOUR AD CODE HERE
</div>
<br />', $message['body'], '</div>
       </div>';