Author Topic: Ad Management on Custom Themes (SMF 1.1.x)  (Read 2578 times)

0 Members and 1 Guest are viewing this topic.

Offline ccbtimewiz

  • Dreamer
  • Guru
  • *
  • Posts: 1304
  • Karma: 2100
  • Gender: Male
  • $info->close();
    • Dream Portal
  • SMF Version: SMF 2.0 RC4
Ad Management on Custom Themes (SMF 1.1.x)
« on: October 25, 2008, 12:31:42 AM »
Ad Management on Custom Themes for SMF 1.1.x
Created by ccbtimewiz

Guide Index
Section I: What is a custom theme?
Section II: How do I edit a theme? What is FTP?
Section III: What should I know before editing the theme?
Section IV: Overview of editing the template
 * ./Themes/{your_theme}/index.template.php [parse]
 * ./Themes/{your_theme}/BoardIndex.template.php [parse]
 * ./Themes/{your_theme}/MessageIndex.template.php [parse]
 * ./Themes/{your_theme}/Display.template.php [parse]




What is a custom theme?

Firstly, a theme in general is the look and feel of the forum. Themes can be switched between by users, and usually have their own HTML, CSS, Javascript, and images. Themes control virtually every visual aspect of SMF, allowing for easier customization.

A custom theme is any theme you use in replacement of the default theme. Modifications through the Package Manager are installed on the default theme's template files. It is quite difficult for a modification's author as well as a theme creator to make their modifications work with other themes especially if they have several of their own template files. When a template file is not found in a custom non-default theme, the theme will rollback and use the default theme's template. However for the template files that the custom theme does use, you will need to manually install the modification on to template files.

The "default" theme is, actually, not the "default theme." while SMF starts out with it as the theme, the "Default" theme is only a collection of the default templates.  That is, these templates are "fallbacks" incase the current theme does not have the template.

This is similar to URLs - if you don't specify a domain name, (ie. /style.css) it uses the default. (making it www.simplemachines.org/style.css)  In this case, it's a bit different, but the concept is the same.

Almost 90% of the time, every theme has their own index.template.php and Display.template.php files. This meaning, in order to use the Ad Management mod, you'll be needing to edit those template files in your theme folder. This guide was made to ease the process of editing those template files.


How do I edit a theme? What is FTP?

In order to actually edit the template files, you'll be needing to actually download the said files from your server and then open them in a programming notepad. This may seem like a daunting task, but this guide is what makes it simple.

Firstly you'll be needing a good FTP client. Likewise you'll need to understand what FTP is and how to operate it.

Refer to the documents on the SMF website as it would take a large amount of time to explain this.

What is FTP? / How do I use FTP? / What are good FTP clients?

For a programming notepad, I highly suggest Notepad++. It's a tool that will make it far easier to program in PHP and it will assist you greatly in making the edits for this mod.

What should I know before editing the theme?

The basic concept of PHP in SMF terms. I'll try my best to explain it and hopefully it will assist you in making the template edits for the mod.

Firstly, SMF is made up of PHP and MySQL. You don't need to worry about MySQL right now, though.

What you need to understand is that whenever you make an edit with solely HTML, you need to be sure it's within an echo() string. The markup for an echo string and most of PHP contain ' and ;.

You'd for example, write a string such as:

:
echo '<div align="center">Hello!</div>';
See? The HTML is inside the echo string and is concatenated between the ' and ' and then it's ended with a ;

However if you're writing something that doesn't have any HTML code, then you need to make sure you echo() out anything that goes after. Such as for example, if the parser said to:

Find:
:
<body>';
But in your template, you had something along the lines of:
:
<body>
 <div id="sag1">
  <div id="sol1">
<div id="alt1">
<div id="altsag1">
  <div id="altsol1">

You cannot simply add the code after. You need to first close the body tag from the echo string so you can write another string or use variables.

So, you'd do:
:
<body>';

{ the ad code }

 <div id="sag1">
  <div id="sol1">
<div id="alt1">
<div id="altsag1">
  <div id="altsol1">

Ah, but can you see now? The rest of the HTML is no longer in an echo() string! It's being treated as variables and that will cause a parse error. You'll be needing to add another echo statement there, like so:

:
<body>';

{ the ad code }

echo '
 <div id="sag1">
  <div id="sol1">
<div id="alt1">
<div id="altsag1">
  <div id="altsol1">

Hopefully you're with me at this point. If you didn't understand feel free to ask questions. I'm more then willing to update this guide to be simpler.

This is about as much as you'd need to know on making edits. If you're interested in learning more about SMF or how PHP works, feel free to look at www.simplemachines.org or go to www.php.net to learn more.


Overview of editing the templates

This is the last part of the guide. Hopefully you've understood what I've been saying so far and that you'll be able to tackle down this editing.

If it doesn't work the first time, your best bet is to keep trying. Ask for help around-- ask people for help and show them what you've coded so far. Don't just ask for someone to do it all for you as then they'd be unwilling to help.

./Themes/{your_theme}/index.template.php

Find:
:
<body>';
Replace with:
:
<body>';

//Display ads on the top of the page
if (function_exists("show_topofpageAds"))
{
$ads = show_topofpageAds();
if(!empty($ads))
if($ads['type']==0)
echo $ads['content'];
else
eval($ads['content']);
unset($ads);
}

Find:
:
</td>
Replace with:
:
</td>';
//Welcome Ads
if (function_exists("show_welcomeAds"))
{
$ads = show_welcomeAds();
if(!empty($ads))
{
echo '<td class="windowbg2">';
if($ads['type']==0)
echo $ads['content'];
else
eval($ads['content']);
echo '</td>';
}
unset($ads);
}
echo '

Find:
:
template_menu();
Replace with:
:
template_menu();

//Below the menu ads
if (function_exists("show_indexAds") && function_exists("show_towerleftAds") && function_exists("show_towerrightAds"))
{
$ads = show_indexAds();
if(!empty($ads))
if($ads['type']==0)
echo $ads['content'];
else
eval($ads['content']);
unset($ads);

//Tower left Ads
$ads = show_towerleftAds();
if(!empty($ads))
echo '<table><tr><td valign="top">', $ads['type']==0 ? $ads['content'] : eval($ads['content']) ,'</td><td width="100%" valign="top">';

unset($ads);
//Tower Right Ads
$ads = show_towerrightAds();
if(!empty($ads))
echo '<table><tr><td width="100%" valign="top">';
unset($ads);
}

Find:
:
// Show the "Powered by" and "Valid" logos, as well as the copyright. Remember, the copyright must be somewhere!

Replace with:
:

//Close table for towerright ads
if (function_exists("show_towerrightAds") && function_exists("show_towerleftAds") && function_exists("show_bottomAds"))
{
$ads = show_towerrightAds();
if(!empty($ads))
echo '</td><td valign="top">', $ads['type']==0 ? $ads['content'] : eval($ads['content']) ,'</td></tr></table>';

unset($ads);
//Close table for towerleft ads
$ads = show_towerleftAds();
if(!empty($ads))
echo '</td></tr></table>';
unset($ads);

//Show ads on the bottom of the page
$ads = show_bottomAds();
if(!empty($ads))
if($ads['type']==0)
echo $ads['content'];
else
eval($ads['content']);
unset($ads);
}

     // Show the "Powered by" and "Valid" logos, as well as the copyright. Remember, the copyright must be somewhere!


./Themes/{your_theme}/BoardIndex.template.php

Find:
:
// Show some statistics next to the link tree if SP1 info is off.
Add Before
:
//Display ads on the board index
if (function_exists("show_boardAds"))
{
$ads = show_boardAds();
if(!empty($ads))
if($ads['type']==0)
echo $ads['content'];
else
eval($ads['content']);
unset($ads);
}

Find:
:
echo '
</div>';

Replace with:
:
echo '
</div>';

//Display ads Between cats
if (function_exists("show_category"))
{
$ads = show_category($category['id']);
if(!empty($ads))
if($ads['type']==0)
echo $ads['content'];
else
eval($ads['content']);
unset($ads);
}


./Themes/{your_theme}/MessageIndex.template.php

Find:
:
global $context, $settings, $options, $scripturl, $modSettings, $txt;
Replace with:
:
global $context, $settings, $options, $scripturl, $modSettings, $txt;

//Display Ads on the Message index
if (function_exists("show_threadindexAds"))
{
$ads = show_threadindexAds();
if(!empty($ads))
if($ads['type']==0)
echo $ads['content'];
else
eval($ads['content']);
unset($ads);
}

Find:
:
echo '
</table>
</div>';

Replace with:
:
echo '
</table>
</div>';

//Display Ads on the Message index
if (function_exists("show_underchildren"))
{
$ads = show_underchildren();
if(!empty($ads))
if($ads['type']==0)
echo $ads['content'];
else
eval($ads['content']);
unset($ads);
}


./Themes/{your_theme}/Display.template.php

Find:
:
global $context, $settings, $options, $txt, $scripturl, $modSettings;
Replace with:
:
global $context, $settings, $options, $txt, $scripturl, $modSettings;

//Display ads on the thread page
if (function_exists("show_threadAds"))
{
$ads = show_threadAds();
if(!empty($ads))
if($ads['type']==0)
echo $ads['content'];
else
eval($ads['content']);
unset($ads);
}

Find:
:
// Get all the messages...
while ($message = $context['get_message']())
{

Replace with:
:
//Ad Counter
$adcounter =0;
// Get all the messages...
while ($message = $context['get_message']())
{
$adcounter++;

Find:
:
</td></tr>';
}

Replace with:
:
</td></tr>';

if (function_exists("show_posts"))
{
if ($adpost = show_posts($adcounter))
{
if($modSettings['ads_lookLikePosts'])
{
echo '

<tr><td style="padding: 1px 1px 0 1px;">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr><td class="windowbg3">
<table width="100%" cellpadding="5" cellspacing="0" style="table-layout: fixed;">
<tr>
<td valign="top" width="16%" rowspan="2" style="overflow: hidden;">
<b>', $context['forum_name'], '</b>
<div class="smalltext">
</div>
</td>
<td valign="top" width="85%" height="100%">
<table width="100%" border="0"><tr>
<td valign="middle"><img src="', $message['icon_url'] . '" alt="" border="0" /></td>
<td valign="middle">
<div style="font-weight: bold;" id="subject_', $message['id'], '">
<a href="', $message['href'], '">', $message['subject'], '</a>
</div>
<div class="smalltext">« <b>', !empty($message['counter']) ? $txt[146] . ' #' . $message['counter'] : '', ' ', $txt[30], ':</b> ', $message['time'], ' »</div></td>
<td align="', !$context['right_to_left'] ? 'right' : 'left', '" valign="bottom" height="20" style="font-size: smaller;">';
if ($context['can_reply'] && !empty($options['display_quick_reply']))
echo '
', $reply_button, '';

// So... quick reply is off, but they *can* reply?
elseif ($context['can_reply'])
echo '
', $reply_button, '';

// Can the user modify the contents of this post?
if ($message['can_modify'])
echo '
', $modify_button, '';

// How about... even... remove it entirely?!
if ($message['can_remove'])
echo '
', $remove_button, '';

// What about splitting it off the rest of the topic?
if ($context['can_split'])
echo '
', $split_button, '';
echo '
</td>
</tr></table>
<hr width="100%" size="1" class="hrcolor" />
<div class="post">', $adpost['type'] == 0 ? $adpost['content'] : eval($adpost['content']) , '</div>
</td>
</tr>
<tr>
<td valign="bottom" class="smalltext" width="85%">
<table width="100%" border="0" style="table-layout: fixed;"><tr>
<td colspan="2" class="smalltext" width="100%">
</tr><tr>
<td valign="bottom" class="smalltext" id="modified_', $message['id'], '">
</td>
<td align="', !$context['right_to_left'] ? 'right' : 'left', '" valign="bottom" class="smalltext">
<img src="', $settings['images_url'], '/ip.gif" alt="" border="0" />&nbsp;', $txt[511], '
</td>
</tr></table>
</tr>
</table>
</td></tr>
</table>
</td></tr>';
}
else
echo '
<tr><td style="padding: 1px 1px 0 1px;">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr>
<td class="windowbg3">', $adpost['type'] == 0 ? $adpost['content'] : eval($adpost['content']) , '</td>
</tr>
</table>
</td></tr>';
}

}

}

if(function_exists("show_lastpostAds") && function_exists("show_posts"))
{
if(($ads = show_lastpostAds()) && !show_posts($adcounter))
{
if($modSettings['ads_lookLikePosts'])
{
echo '

<tr><td style="padding: 1px 1px 0 1px;">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr><td class="windowbg3">
<table width="100%" cellpadding="5" cellspacing="0" style="table-layout: fixed;">
<tr>
<td valign="top" width="16%" rowspan="2" style="overflow: hidden;">
<b>', $context['forum_name'], '</b>
<div class="smalltext">
</div>
</td>
<td valign="top" width="85%" height="100%">
<table width="100%" border="0"><tr>
<td valign="middle">&nbsp;</td>
<td valign="middle">
&nbsp;</td>
<td align="', !$context['right_to_left'] ? 'right' : 'left', '" valign="bottom" height="20" style="font-size: smaller;">';
if ($context['can_reply'] && !empty($options['display_quick_reply']))
echo '
', $reply_button, '';

// So... quick reply is off, but they *can* reply?
elseif ($context['can_reply'])
echo '
', $reply_button, '';


echo '
</td>
</tr></table>
<hr width="100%" size="1" class="hrcolor" />
<div class="post">', $ads['type'] == 0 ? $ads['content'] : eval($ads['content']) , '</div>
</td>
</tr>
<tr>
<td valign="bottom" class="smalltext" width="85%">
<table width="100%" border="0" style="table-layout: fixed;"><tr>
<td colspan="2" class="smalltext" width="100%">
</tr><tr>
<td valign="bottom" class="smalltext" id="modified_', $message['id'], '">
</td>
<td align="', !$context['right_to_left'] ? 'right' : 'left', '" valign="bottom" class="smalltext">
<img src="', $settings['images_url'], '/ip.gif" alt="" border="0" />&nbsp;', $txt[511], '
</td>
</tr></table>
</tr>
</table>
</td></tr>
</table>
</td></tr>';
}
else
echo '
<tr><td style="padding: 1px 1px 0 1px;">
<table width="100%" cellpadding="3" cellspacing="0" border="0">
<tr>
<td class="windowbg3">', $ads['type'] == 0 ? $ads['content'] : eval($ads['content']) , '</td>
</tr>
</table>
</td></tr>';

}

}
« Last Edit: October 25, 2009, 02:10:43 AM by bigguy »

Offline AST3R1X

  • V.I.P.
  • *
  • Posts: 1210
  • Karma: 1002
  • Gender: Male
    • Demon Pixels
  • SMF Version: SMF 2.0 Gold
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #1 on: October 25, 2008, 06:20:58 AM »
Thats a good easy to follow guide ccb. Thanks  :)

Offline brianjw

  • Guru
  • *
  • Posts: 2346
  • Karma: 1408
  • Gender: Male
  • What?!?! You mean they're sold out!
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #2 on: October 25, 2008, 09:53:43 AM »
Thanks for posting this ccb; this will help alot. :)

Offline masterthug61

  • New Member
  • *
  • Posts: 4
  • Karma: 0
  • Gender: Male
  • SMF Version: 1.1.6
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #3 on: November 05, 2008, 11:35:37 AM »
Hello, in the second part of inserting the code after </td> in
./Themes/{your_theme}/index.template.php , which </td> does the code go after? I have many </td>s in mine. Thanks!

Offline bigguy

  • Site Owner
  • Administrator
  • *
  • Posts: 13217
  • Karma: 269
  • Gender: Male
  • Get'r Done
    • P.C. Tweakr
  • SMF Version: 2.0 Gold
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #4 on: November 05, 2008, 11:42:19 AM »
Check the default index.template.php if you have the mod installed to find where it should go in a custom theme.

Offline Nabil

  • New Member
  • *
  • Posts: 21
  • Karma: 1
  • SMF Version: 1.1.8
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #5 on: December 18, 2008, 08:44:05 AM »
hi , I'm asking the same question asked by masterthug61 WHICH </td> ?

Check the default index.template.php if you have the mod installed to find where it should go in a custom theme.
My custom Theme Index.template.php look mostly different than the Default index.template , I found that </td> on the Default Index.template.php but like I said it is different , you cannot compare it with the Index.template of my custom Theme so WHICH </td> ?
« Last Edit: December 18, 2008, 08:55:28 AM by Nabil »

Offline bigguy

  • Site Owner
  • Administrator
  • *
  • Posts: 13217
  • Karma: 269
  • Gender: Male
  • Get'r Done
    • P.C. Tweakr
  • SMF Version: 2.0 Gold
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #6 on: December 18, 2008, 10:28:38 AM »
Compare the area around the </td> in the default to your custom theme. Usually the code around it will be the same.

Offline Nabil

  • New Member
  • *
  • Posts: 21
  • Karma: 1
  • SMF Version: 1.1.8
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #7 on: December 18, 2008, 01:22:49 PM »
This Mod would not go with my Theme , it is a very weak mod , and sorry to say that the developer of it thought only of the Default Theme , I have installed many Mods till now , non of them added in the Index.template.php more than the button function no more than that , Only in this Mod adding something after </td> WHAT is </td> is this a point where you can guide somebody to do something ??
« Last Edit: December 18, 2008, 02:37:35 PM by Nabil »

Offline bigguy

  • Site Owner
  • Administrator
  • *
  • Posts: 13217
  • Karma: 269
  • Gender: Male
  • Get'r Done
    • P.C. Tweakr
  • SMF Version: 2.0 Gold
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #8 on: December 18, 2008, 01:36:10 PM »
I have installed this mod on probably well over 30 themes. All the edits do NOT have to go in. if you leave that edit out it will not break the mod. You just won't have that particular place to show ads. Also, keep in mind that all mods only install to the default theme. This is not an oversight of the mod author. This is the way all mods are developed. This is more along the lines of the theme you are using is so different that the author of said theme has changed it so drastically that most of the code is gone.

Offline ccbtimewiz

  • Dreamer
  • Guru
  • *
  • Posts: 1304
  • Karma: 2100
  • Gender: Male
  • $info->close();
    • Dream Portal
  • SMF Version: SMF 2.0 RC4
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #9 on: December 18, 2008, 02:46:32 PM »
I've assisted with the development and lead the support for this mod and I can say that this about question about the </td> has been asked multiple times.

We completely understand what the confusion is, but you need to understand that the SMF Package Manager reads white-space exactly, so all spaces are taken into account. The Package Manager is able to correctly find that one <td> with approx 120 spaces, but that might be difficult for a human. When I update this guide along with creating the 2.0 guide I'll be sure to include instructions meant for humans rather than the Package Manager.

On regards to custom themes, it's near impossible to facilitate this modification to work properly on every single theme as every theme author styles their headers/footers differently. Likewise the header/footer of a theme is a popular spot for other mods to edit and for forum owners to add their own code to (like extensions, images, affiliates, etc).

We plan on creating a compiled list of edits for every popular theme out there on the main support site for the mod (http://smfads.com) so users can download the ad-mod integrated version of their theme before making their own personal edits.

We apologize for the inconvenience and hope that we will be able to make your experiance with the Ad Management a positive one. If you would attach your index.template.php from your theme, I'll make the edits for you.

Offline bigguy

  • Site Owner
  • Administrator
  • *
  • Posts: 13217
  • Karma: 269
  • Gender: Male
  • Get'r Done
    • P.C. Tweakr
  • SMF Version: 2.0 Gold
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #10 on: December 18, 2008, 03:34:49 PM »
Your compiling a list of edits for every popular theme are ya. ??? Thats going to be a bit of work. Also that </td> does not exist in every theme.

Offline ccbtimewiz

  • Dreamer
  • Guru
  • *
  • Posts: 1304
  • Karma: 2100
  • Gender: Male
  • $info->close();
    • Dream Portal
  • SMF Version: SMF 2.0 RC4
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #11 on: December 18, 2008, 04:08:11 PM »
It absolutely will be a bit of work, but it will certainly lighten the load of support questions.

Also, as I said, theme authors can code their templates differently. :)

Offline bigguy

  • Site Owner
  • Administrator
  • *
  • Posts: 13217
  • Karma: 269
  • Gender: Male
  • Get'r Done
    • P.C. Tweakr
  • SMF Version: 2.0 Gold
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #12 on: December 18, 2008, 04:40:07 PM »
They usually do. I have slowed way down on giving support for the ad mod. Been doing it a long time now. :)

Offline vanquizhers

  • New Member
  • *
  • Posts: 3
  • Karma: 29
  • Gender: Male
    • Indonesia Crew
  • SMF Version: 1.1.10
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #13 on: August 13, 2009, 12:24:38 AM »
Hi guys, why I always error when inserting

   template_menu();

   //Below the menu ads
   if (function_exists("show_indexAds") && function_exists("show_towerleftAds") && function_exists("show_towerrightAds"))
   {
      $ads = show_indexAds();   
      if(!empty($ads))
         if($ads['type']==0)
            echo $ads['content'];
         else
            eval($ads['content']);
      unset($ads);

      //Tower left Ads
      $ads = show_towerleftAds();
      if(!empty($ads))
         echo '<table><tr><td valign="top">', $ads['type']==0 ? $ads['content'] : eval($ads['content']) ,'</td><td width="100%" valign="top">';

      unset($ads);
      //Tower Right Ads
      $ads = show_towerrightAds();   
      if(!empty($ads))
         echo '<table><tr><td width="100%" valign="top">';
      unset($ads);
   }   

in index.template.php

can somebody help me to edit my index.template.php ?
I attach in attachment.
Thank You.

Offline vanquizhers

  • New Member
  • *
  • Posts: 3
  • Karma: 29
  • Gender: Male
    • Indonesia Crew
  • SMF Version: 1.1.10
Re: Ad Management on Custom Themes (SMF 1.1.x)
« Reply #14 on: August 13, 2009, 12:26:42 AM »
there a no  template_menu(); in my index.template.php, just only ',template_menu(),'

and I use SMF version 1.1.10 and my theme Outline by dzinerstudio
Thank You...  :)
« Last Edit: August 13, 2009, 06:00:24 AM by vanquizhers »