Simple Machines Community Forum

Customizing SMF => Tips and Tricks => Topic started by: Suki on March 07, 2011, 01:28:27 PM

Title: [Tip] Showing ads or text inside the message without template edits
Post by: Suki on March 07, 2011, 01:28:27 PM
This is rather a simple tip for showing ads, text, images, custom code, etc  before or after the message in  every message or just the first one,  doing it on Source means  that no matter what theme you're using, it will work on that or any other theme,  this tip can be used in either 1.1.x or 2.0.

first we open our /Sources/Display.php  and find this line

// Do the censor thang.


and above that add this:

// Let's define some parameters
// by default the ad will appear on the first page and before the message,
// you can configure the parameters on the array below

$opciones = array(
'primer_tema' => true,   // false for showing on every message, true for showing only in first message
'espacio' => '<p />',    // an space is required to properly separate the ad from the message
'antes' => true,      // true show the ad before the message,  false show it after the message
);
   
$codigo = 'your code';   // here you can write your code, remember to properly escape single quotes '  like this \' 
   
   
// We put the ad with the body together. here the ad will be before the body on first message
if ($counter == 0 && $opciones['primer_tema'] == true && $opciones['antes'] == true)
$message['body'] = ('' . $codigo . $opciones['espacio'] .$message['body']);

//   Here the ad will be showed on all messages before the body
if ($opciones['primer_tema'] == false && $opciones['antes'] == true)
$message['body'] = ('' . $codigo . $opciones['espacio'] .$message['body']);

//   Here the ad will be showed after the body on first message only
if ($counter == 0 && $opciones['primer_tema'] == true && $opciones['antes'] == false)
$message['body'] = ('' . $message['body'] . $opciones['espacio'] . $codigo);

//   Here the ad its showed after the body on all messages
if ($opciones['primer_tema'] == false && $opciones['antes'] == false)
$message['body'] = ('' . $message['body'] . $opciones['espacio'] . $codigo);




the code has comments and its pretty simple to understand:

'primer_tema' => true,     if true, the ad will appear only in the first message,   write false  if you want the add to appear on every message

'espacio' => '<p />',   a simple <p />  tag to separate the ad from the actual message.

'antes' => true,   if true, the ad will appear before the message's body,  write false  to show the ad after the message's body.


thats pretty much it!  now the ad will appear  right before or after the message's body in every theme you use.
Title: Re: [Tip] Showing ads or text inside the message without template edits
Post by: Biology Forums on March 07, 2011, 02:08:01 PM
Can you show us an example :)?
Title: Re: [Tip] Showing ads or text inside the message without template edits
Post by: Matthew K. on March 07, 2011, 02:42:40 PM
Moved to Tips and Tricks for ya, Miss All Sunday :)
Title: Re: [Tip] Showing ads or text inside the message without template edits
Post by: Suki on March 07, 2011, 02:47:51 PM
Quote from: Labradoodle-360 on March 07, 2011, 02:42:40 PM
Moved to Tips and Tricks for ya, Miss All Sunday :)

thanks ;)

Quote from: shuban on March 07, 2011, 02:08:01 PM
Can you show us an example :)?


you mean a screen shot or a live forum example?
Title: Re: [Tip] Showing ads or text inside the message without template edits
Post by: Biology Forums on March 07, 2011, 02:51:58 PM
Yeah, exactly.
Title: Re: [Tip] Showing ads or text inside the message without template edits
Post by: paketdigital on March 08, 2011, 05:54:59 AM
How smart is that during my search. thanks a lot friend ;D

Title: Re: [Tip] Showing ads or text inside the message without template edits
Post by: Maever on March 08, 2011, 08:05:43 AM
Great stuff, nice tip.
Title: Re: [Tip] Showing ads or text inside the message without template edits
Post by: morean51 on March 09, 2011, 02:06:07 AM
good tip thank you for it