Integrating SMF with your website

[b]Update: An extended version of this guide is now available at http://www.simplemachines.org/community/index.php?topic=145838.0[/b] [hr]

In many cases, people want their forum to look like their main site. To make this possible might take a little bit of work, but it really isn't all that difficult.

The first step is to know some basic CSS and HTML. If you don't know these, and cannot bother to learn them, I hope you're willing to pay someone to help you. Learning just basic CSS and HTML isn't that difficult, and the benefits are wonderful and great; I'm not writing this for those who want things handed to them on silver platters. Sorry to those who don't for having to say that.

Some guides on CSS and HTML are available here: http://www.w3schools.com/html http://www.w3schools.com/xhtml http://www.w3schools.com/css

When I say HTML, I really mean XHTML, but the difference is more like a new version than a separate language. XHTML is preferred, but if you know HTML it should be fine. For more information on them and their differences, see the tutorials above.

Next, you'll want to 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" and click Install! You will be prompted to click OK - please do so.

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.

After this is done, you can use the style.css in your theme's directory to customize most of the colors. Of course, this isn't exactly what you're looking for, but bare with me and get those customized. There are comments in the file, but the main ones to worry about are titlebg (blue), windowbg and windowbg2 (shades of gray), and bordercolor/tborder. (backgrounds for tables, grid lines, etc.)

[b][size=larger]Moving to Your Layout[/size][/b]

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 don't, 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" - don't worry, they don't 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:

[code]  ', $context['page_title'], ' ';

if ($context['browser']['needs_size_fix']) echo '  ', $context['html_headers'], ' [/code]

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 should be a [tt]';[/tt]. Make sure to leave that there. After that line, add:

[code]include('header.php');[/code]

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:

[code]

[/code]

Again, don't remove that last [tt]';[/tt] 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: [code] [/code]

Above that, you will see a line that says [tt]echo '[/tt] - and, above that, we want to add:

[code]include('footer.php');[/code]

Again, if you put the outside the forum's directory, you'll want to use ../ to "get to it". That was the basic method.

I'll post the more advanced method in a reply.

-[Unknown]

[b][size=larger]The Cooler Way[/size][/b]

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 don't 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 [tt]?>[/tt], add: [code]function template_site_above {	global $context, $settings, $options, $scripturl, $txt, $modSettings;

echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">   ', $context['page_title'], ' ';

if ($context['browser']['needs_size_fix']) echo '  ', $context['html_headers'], ' ';

include('header.php'); }

function template_site_below {	global $context, $settings, $options, $scripturl, $txt, $modSettings;

include('footer.php');

echo ' '; }[/code]

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're 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:

[code]

[/code]

Again, don't remove that last [tt]';[/tt] 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: [code]echo '<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">[/code]

To: [code] ';[/code]

And then removing: [code]	echo ' ';[/code]

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:

[code]REPLACE INTO yourprefix_themes (ID_THEME, variable, value) VALUES (that number, 'theme_layers', 'site,main');[/code] (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:

[code]<?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;

?>[/code] (where that pesky number again is the theme id, and forum/SSI.php is where ever SSI.php is - not a URL.)

I'll admit 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.

Good luck! Tell me if you have problems... (in this topic please, I get too many pms...)

-[Unknown]

OP: http://www.simplemachines.org/community/index.php?topic=19638.0