Using HTML Templates
The following applies to using HTML templates with sNews.
Once you have sNews up and running on your server, be it local or remote, you will probably want to work it into your own site construction. Well, thanks to sNews’ construction, doing this is very easy. The simplest way of all is to use the XHTML index file that is included in the sNews package you downloaded from the sNews website—this basic template has all the necessary sNews functions already in it.
But if you want to use your own existing XHTML document instead? Or, if you want to use one of the many free webpage templates available? No worries, here’s a quickstep checklist that you can follow.
1. Start Your Session
The very first thing you want to do is make sure that your template or own site design’s index file is a php-html document, e.g is called “index.php”. To make it easier for yourself, you should also make sure that you have snews.php and index.php in the same folder. Done? OK, open index.php in your good text editor and place the following php string at the top of your document.
<?php session_start(); include('snews.php'); ?>
Make sure nothing comes before this string—no empty line, no blank space, nothing.
2. The site title
Next, find and destroy the <title> tag. Replace it with this code:
<?php title(); ?>
The <?php title(); ?> function adds the following bits to your index.php, using the information you have entered in snews.php:
- Base href – the root of your site, equals the $db['website'] value
- Title – the name of your website that appears in the browser window’s title bar
- The Description meta tag – the general site description, enter it in the Admin panel
- The Keywords meta tag – the general keywords for your site, you enter them in the Admin panel
It’s important to remember that <?php title(); ?> must come before any stylesheet, script, favicon or rss feed links; otherwise these details may not work because the base href hasn’t been set before them. So, order is important. Put <?php title(); ?> at the top of the <head>.
3. Site Navigation
There are a couple of functions in snews.php that can act as site navigation, i.e <?php pages(); ?> and <?php categories(); ?>, where pages() includes the home page, contact page, archive page, site map and any other (static) page you create; and categories() includes home and any other category you create. Both of these functions can act as the main navigation – it’s really up to you which one to use. Unless you elect to use both, of course... ;)
Other functions that are “navigational” include <?php menu_articles(); ?> (lists recent articles), <?php new_comments(); ?> (lists recent comments) and <?php breadcrumbs(); ?>. As you can see, you have complete control over the presentation of the content since you can place these functions just about anywhere you like in the <body> By default, pages(), categories(), menu_articles and new_comments() are presented in unordered lists (<ul>) and some of these functions have their HTML output hardcoded into snews.php, which means that modifications of the HTML will need to take place there.
4. Front and center()
One of the most important functions to include in your index.php file—one that you do not want to leave out is the <?php center(); ?> function. Not only does it act as the container for your articles —i.e the main content— but it also doubles as the main Admin area. If you exclude center(); it’s probable that you won’t get any login form, for example. (Unless of course you put the function <?php login(); ?> somewhere on your page, but there’s a better way for that. Use center() and add <?php login_link(); ?> in some inconspicuous place on your page, like one of the top or bottom corners.)
Other useful functions include <?php searchform(); ?>, <?php extra(); ?> (container for extra, static content) and the already mentioned <?php login_link(); ?>.
5. Summary
To summarize: Start your document with <?php session_start(); include('snews.php'); ?>, don’t put anything before this string. Put <?php title(); ?> directly after the opening <head> tag. Use <?php pages() ?> or <?php categories() ?> for your main site navigation. And, whatever you do, don’t forget the <?php center() ?> function. The rest is up to you.

11 Feb, 2008
Views: 1272


