Creating Templates

1. Introduction
2. The parts of the template
    2.1 Using CSS for modules
    2.2 Title of your site
    2.3 Location
    2.4 Section menu
    2.5 Submenu
    2.6 Page content
    2.7 Logoff link
    2.8 Return to public site link
    2.9 Last news link
    2.10 Automatically show when your site was updated
    2.11 Category template

1. Introduction

When you want to change or create a new template you must have a fair knowledge of HTML and know how to integrate PHP code into HTML

The templates are located in ../starnet/themes/ directory. You can create a directory of your choice and all the template files have to be copied in this directory. The template directory name will automatically show up in the SyndeoCMS management. The file main.inc.php contains a mix of HTML and PHP, where the PHP scripts take care of creating the menu bars and filling the page content. The filename main.inc.php is fixed because it is called by the CMS.
The standard template is a basic example which can be used as a starting point.

IMPORTANT:
Always use the following code on top of your main.inc.php file:

<?php
if ( !defined('IN_SAS') )
{
	die("Hacking attempt");
}
?>

This will prevent that the main.inc.php can be called from outside the CMS.
 

2. The parts of the template

2.1 Using CSS for modules

In SyndeoCMS version 2.5 you can use CSS to manage the style of the modules , see CSS in the manual.

If you want to manage the CSS on a module basis you need to add the following php to your template, just after the html head tag and just after your normal loading of stylesheet file.

<?php 
include($cmsdir."/core/css.php"); 
?>

2.2 Title of your site

This will print your site name and page title in your browser:

<title><?php print "$sitename - $pagetitle"; ?></title>

Example:

2.3 Location:


This will print a line with the current site location:

<?php
$query = "SELECT name FROM $table_sections WHERE id = '".$section."'";
$result = mysql_query($query);
$sectionname = mysql_result($result,0);
unset($query);
unset($result);
print "location: $sectionname -> $pagetitle";
?>

 Example:

[ ]

2.4 Section menu

This will create the menu items for the section menu:

 

  • First example:
    <?php
    $query = "SELECT id, name, frontpage FROM $table_sections WHERE invisible != 'yes' ORDER BY sort"; 
    $result = mysql_query($query);
    while ($section_menu = mysql_fetch_array($result))
    {
    	if ($section_menu[0] == $section)
    	{
    	print "<b>$section_menu[1]</b>
    		<img src=\"$cmsdir/themes/$themelocation/menupoint.gif\" width=\"6\" height=\"6\" alt=\"\"><br />";
    	}
            else
    	{
    	print "<a href=\"index.php?section=$section_menu[0]&page=$section_menu[2]\">$section_menu[1]</a>
    		<img src=\"$cmsdir/themes/$themelocation/menupoint.gif\" width=\"6\" height=\"6\" alt=\"\"><br />";
    	}
    }
    ?>

    The first print of a section menu item is the current section and is made bold in this example.
    The menupoint.gif can of course be replaced by your own gif.
  • Second example:
    <?php
    $query1 = "SELECT id, name, module FROM $table_pages WHERE section = '".$section."' 
    AND invisible != 'yes' ORDER BY sort";
    $result1 = mysql_query($query1);
    
    while ($page_menu = mysql_fetch_array($result1))
    {
    	if($page_menu[0] == $page) 
    	{
    		print "<a href=\"#\">$page_menu[1]</a><br />";
    	} 
    	elseif(substr($page_menu[2],0,5) == "http:") 
    	{
    		print "<a href=\"$page_menu[2]\" target=\"_blank\">$page_menu[1]</a><br />"; 
    	} 
    	elseif(substr($page_menu[2],0,5) == "file:") 
    	{
    		$link = substr($page_menu[2],7)  ;
    		print "<a href=\"$link\" target=\"_blank\">$page_menu[1]</a><br />";
    	} 
    	else 
    	{
    		print "<a href=\"index.php?page=$page_menu[0]&amp;section=$section\">$page_menu[1]</a><br />";
    	}
    	
    }
    ?>

    This second example makes it possible to create a menu item with a link inside or outside the CMS.
    For this purpose we use the module field in a special way when creating the page:

    Instead of specifying a module name we give a valid http address. The PHP code in the template checks for http: (lowercase) and if it finds it, it will create a menu link with this http address.

    The same can be done for a file, you fill in a link like:
    file://www.yourlink.com/starnet/media/somefile.txt

    2.4 Submenu

    This creates the menu items for the pages of a section:

    [ ]

    <?php
    $query1 = "SELECT id, name FROM $table_pages WHERE section = '".$section."' AND invisible != 'yes' ORDER BY 
    
    sort";
    $result1 = mysql_query($query1);
    while ($page_menu = mysql_fetch_array($result1))
    {
    	if($page_menu[0] == $page)
    	
    
    {
    	print "<tr height=\"25\"><td width=\"20%\" align=\"right\">
    <img border=\"0\" src=\"starnet/themes/standard/nblt.gif\" width=\"6\" height=\"12\"></td>";
    	print "<td width=\"80%\" background=\"starnet/themes/standard/menu-bg2.gif\"><font size=\"2\">";
    	print "$page_menu[1]</font></td></tr>";
    	}
    	else
    	{
    	print "<tr height=\"25\"><td width=\"20%\" align=\"right\">
    <img border=\"0\" src=\"starnet/themes/standard/nblt.gif\" width=\"6\" height=\"12\"></td>";
    	print "<td width=\"80%\" onMouseOver=\"this.background='starnet/themes/starnet/menu-bg2.gif'\" onMouseOut=\"this.background=''\">
    <font size=\"2\">";
    	print "<a href=index.php?page=$page_menu[0]&section=$section>$page_menu[1]
    
    </a></font></td></tr>";
    	}
    }
    ?>

    This example assumes that the menu bar is part of a table, the other HTML is left out to keep the example simple. The nblt.gif(little arrow) is a small gif, which is located in the standard theme directory.

    2.5 Page content

    This will create the important part, the real contents of a page:

    <?php
    $query = "SELECT module, content FROM $table_pages WHERE id = '".$page."'";
    $result = mysql_query($query);
    $module = mysql_result($result,0,0);
    $content = mysql_result($result,0,1);
    unset($query);
    unset($result);
    
    if($module != '')
    {
      include("starnet/modules/$module");
    }
    else
    {
      $content = str_replace("../","",$content);
      print $content;
    }
    ?>

    The first part checks to see if an installed module is called (e.g. guestbook or mail page). If this is not the case a normal HTML content is read FROM the MySQL table.

    2.6 Logoff link

    This example creates a logoff link.

    
    <?php
    if(IsSet($_SESSION['userid']))
    {
      print "<a href=\"index.php?section=$section&page=$page&logout=yes\">".$sas_lang['logout']."</a>";
    }
    ?>

    2.7 Return to public site link

    This example creates a public site link which can be used to return to the public site from the protected site, without being logged off.

    
    <?php
    if($_SESSION['site'] == "protected")
    {
      print "<a href=\"index.php?section=$_SESSION[section_came_from]&page=$_SESSION[page_came_from]&site=public\">".$sas_lang['public_area']." /</a>";
    }
    ?>

    2.8 Last news link

    This example takes the title of the last created news item and shows a link:

    
    <?php
    $newstable = $dbprefix."m_news_articles" ;
    if($_SESSION['site'] == "protected")
    {
      $query = "SELECT title,date FROM $newstable WHERE public = 1 AND archive = 0 ORDER BY id DESC LIMIT 1";
    }
    else
    {
      $query = "SELECT title,date FROM $newstable WHERE public = 0 AND archive = 0 ORDER BY id DESC LIMIT 1";
    }
    
    $result = mysql_query($query) or die_script($query,mysql_error());
    if(mysql_num_rows($result) > 0) 
    {
      $newstitle = mysql_result($result,0);
      print "<a class=\"mainmenu\" href=\"index.php?section=xx&page=yy\">Latest news: 
      <b>$newstitle<b>$newstitle</b></a>" ;
    }
    ?>

    Where 'xx' is the page number and 'yy' is the page number where your news page is on the site.

    2.9 Automatically show when your site was updated

    When a page is added or changed, SyndeoCMS will store the date of this action into the database.
    Use the following to show it on the bottom of the page, e.g.:

    <?php
     $query = "SELECT config_value FROM $table_configuration WHERE config_key = 'last_update_date'";
     $result = mysql_query($query);
     $date1 = mysql_result($result,0);
     unset($query);
     unset($result);
     print "Site last updated on : $date1" ;
    ?>

    SyndeoCMS also stores the last update date per page, you can use the code below to display a "page last changes on yyyy-mm-dd" text.

    <?php
    $query = "SELECT unix_timestamp(lastupdate) FROM $table_pages WHERE id = '".$page."'";
    $result = mysql_query($query);
    $date = mysql_result($result,0);
    unset($query);
    unset($result);
    $date = strftime($sas_config['dateformat'],$date);
    print "© $sitename , page last changed on $date "; 
    ?>
    
    this will give : "© sitename , page last changed on 01-02-2007"


    2.10 Category template

    The category template uses the category field to create an extra menu level in the pop-up menu on the left side of the screen.
    When you fill in the category field it is possible to create a pop-up menu like this:

     

    In the above example the "info" and "School" are the categories used to group pages under the section "School info". See the category template for coding example in starnet/themes/category/main.inc.php.