Integrating SMF with your website From Online Manual
|If you want to bridge your forum with another software installation on your server, please see Bridging|
Integrating Your Site and Forum - Visually
If you already have a main site and are now adding a forum, you would probably like it to look like your main site. This might take a little work, but it isn't all that difficult. This tutorial assumes you want to begin with a copy of the default theme. If, instead, you want to make a copy of a different theme, the process is not all that different.
The first step is to know some basic CSS and HTML. Pick a favorite tutorial site and visit often as you work through this little project. SMF uses XHTML, which has only a few differences from older flavors of HTML. Your favorite tutorial will explain the differences, and you can always use the W3C markup validation service to check your work. Use your browser's "F12" developers' tools to select an element on the page to figure out which CSS classes have been applied so you can figure out which color, image, or other CSS tool has been applied to it.
Second, make a copy of the default theme. To do this, go into your administration center, and select "Theme and Layout Settings". From there, under "Install a New Theme", type a name for your theme next to "Create a copy of Default named", click Install!, and then choose "OK" when prompted.
Now you have a copy of the default theme. If you want to customize the images for your theme, go to the theme's settings and change the URL from default/images to "yourname"/images, and use an FTP client to copy the files from default into your theme.
Third, do a little work on the colors, in your main CSS file. In SMF 2.0, you'll find this in css/index.css. (in SMF 1.1.x, this was in style.css). Most of the colors you are interested are found in classes catbg and catbg2 (category titles) titlebg, titlebg2 (title bars), windowbg, windowbg2, windowbg3 (post contents), and tborder (table grid lines). Choose colors that match the "skin" of your main site.
Moving to Your Layout
The next step is, of course, to make it look like your site. I assume that, to do this, you already have a "template" of sorts made out of html - your site without the main content. If you do not, making one would help markedly, but you may be able to wing it too.
Once you have this done, you'll want to split it into two parts: the header, and the footer. Doing this makes it much easier to customize things, and can even make it easier to design your own site (with basic shtml or PHP includes.) Put these two parts in a "header.php" and "footer.php" - do not worry, they do not have to have HTML in them at all, but they can.
The next step can be done in two separate ways. One is cleaner, and makes it easier to use SSI to power your site (as is done here.) The other is notably simpler and easier. I'll cover the simpler one first.
You may notice that there's a lot of stuff in the header of the index template. Much of this can be omitted, which is what we're going to do for simplicity's sake. So, what we need to do is find the following:
And keep going down until:
Delete it all. We're going to start fresh, and simpler. All you really need is: (note that this will screw up mutliple language support!)
That's probably less scary, right? If you want the things we just took out (which make browsing better in cases, and internationalization better, etc.) it can be left in. Now, after the <body> should be a
';. Make sure to leave that there. After that line, add:
If you didn't put header.php in the same place as the forum, you may need to make it '../header.php'. After that, we're going to remove the upshrink part (assuming you remove the above part) because it won't work anymore. That means removing:
<a href="#" onclick="shrinkHeader(!current_header); return false;"><img id="upshrink" src="', $settings['images_url'], '/', empty($options['collapse_header']) ? 'upshrink.gif' : 'upshrink2.gif', '" alt="*" title="', $txt['upshrink_description'], '" style="margin: 2px 0;" border="0" /></a><img id="upshrinkTemp" src="', $settings['images_url'], '/blank.gif" alt="" style="margin-right: 2ex;" />
Again, do not remove that last [code]';[/code] because it makes things work. Okay, so we're almost done now. The next step is to add the footer. To do that, look for:
Above that, you will see a line that says
echo ' - and, above that, we want to add:
Again, if you put the outside the forum's directory, you'll want to use ../ to "get to it". That was the basic method.
The Cooler Way - Layers
This other way, we're going to use what are called "layers". Because of this, we will need to make a small change to the database. If you do not have a way to get to the database, such as phpMyAdmin, you may wish to install and learn how to use it (phpMyAdmin, I mean.)
So, the first step is to create the "layer" itself. A layer is simply two sub templates that go above and below the content. For example, by default the 'main' layer is used, which means that above the main part of the page 'main_above' will be shown... and below, 'main_below' will be shown. Not too difficult, right?
So, creating the layer only means creating two sub templates. At the end of index.template.php, right before the
Again, if you have the header.php and footer.php files outside of your forum directory, you may have to change those lines slightly to point things to them. So, if they are in your site's directory, just outside the forum directory, use ../header.php and ../footer.php.
The next step is to remove the shrink thing, since it won't work. As said above, find and remove:
Again, do not remove that last
'; because it makes things work.
Now, in the templates it was using before, you need to remove the header and footer parts. This means removing everything from:
echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
And then removing:
echo ' </body> </html>';
Now, if you did this, and went to your forum, it'd look REALLY CRAPPY. There's one last vital thing that needs to be done for it to work. And to do that, we need the id of the theme we're working with.
To find this id (which, if you've only created one theme, will be 3) you will need to check the link to "preview" it in your profile. You'll see it say "theme=xyz". The number (I put xyz but it should be a number) is the id. Once you have that, you want to write the following query in phpMyAdmin - go to your database and pick the SQL tab, and type in the box:
REPLACE INTO yourprefix_themes (ID_THEME, variable, value) VALUES (that number, 'theme_layers', 'site,main');
(where yourprefix_ is your prefix, often 'smf_' and that number is the theme id we found.)
By the by, if you're wanting to distribute your theme, and use layers, look in the file named "theme_info.xml". It has a special spot just for this information. Remember that the layers are loaded in the order listed - in this case, it goes site_above -> main_above -> content -> main_below -> site_below.
Wonderful. You're done, and everything looks fancy. But, now, you probably did this to use it with SSI - how does one do that? Try the following code, in a PHP file:
<?php error_reporting(E_ALL); $ssi_theme = that pesky number again; $ssi_layers = array('site'); // If you want SSI.php to start gzipping for you ;). $ssi_gzip = true; require('forum/SSI.php'); echo 'some stuffs go here.'; ssi_shutdown(); ?>
(where that pesky number again is the theme id, and forum/SSI.php is where ever SSI.php is - not a URL.)
A more complicated system is used for this site, but the example given should be more than enough to help you power everything through SMF and its template system, should you wish to.