Theming
Theming had always been my challenging topics while creating my cms.Thanks to the social networking sites through which I learned my first lessons on how to manage themes for a site.Before we get into theming,just think about "what kind of look does our site require?".For easy understanding,I am just concentrating on a blog based cms where admin can post,edit blogs.
The theme for our cms will be
///////////////////////////////////////////////////////////
default/
images/
site_logo.gif
include/
header.php
footer.php
index.php
css.php
////////////////////////////////////////////////////////////
Now we can take a look at theme_class.php
Here are the description of the methods used.
Theming had always been my challenging topics while creating my cms.Thanks to the social networking sites through which I learned my first lessons on how to manage themes for a site.Before we get into theming,just think about "what kind of look does our site require?".For easy understanding,I am just concentrating on a blog based cms where admin can post,edit blogs.
The theme for our cms will be
- simple
- easily editable
- high speed loading
- header ----- with a sitelogo.
- body ---------- containing views from modules.
- footer --------- to show credits.
///////////////////////////////////////////////////////////
default/
images/
site_logo.gif
include/
header.php
footer.php
index.php
css.php
////////////////////////////////////////////////////////////
Now we can take a look at theme_class.php
- open stupid >>> include directory.
- create a file and name it as theme_class.php
- open the file in an editor and write the following code.
<?php class Theme { var $active_theme; function Theme() { $this->active_theme=$this->get_active_theme(); } function get_active_theme() { global $db; $sql="SELECT * FROM settings"; $res=$db->query($sql); $settings=$db->fetch_array($res); $active_theme=$settings['theme']; return THEMESPATH."/".$active_theme; } function set_active_theme($name) { global $db; $sql="UPDATE `settings` SET `theme`='".$name."' WHERE 1"; if($db->query($sql)) { return; } } function get_themes_list() { $themes = array(); if ($handle = opendir(THEMESPATH)) { while ($t = readdir($handle)) { // must be directory and not begin with a . if (substr($t, 0, 1) !== '.' && is_dir(THEMESPATH . "/" . $t)) { $themes[] = $t; } } } sort($themes); return $themes; } function get_sitelogo() { return BASE.'/'.$this->active_theme.'/images/site_logo.gif'; } function load_index() { include $this->active_theme."/index.php"; } function load_css() { include $this->active_theme."/css.php"; } function load_footer() { include $this->active_theme."/include/footer.php"; } } ?>
Here are the description of the methods used.
- Theme ==> constructor assigns variable active_theme with the name of the current active theme.
- get_active _theme ==> gets the name of the current active theme from the database.
- set_active_theme ==> sets the value of active_theme field in the settings table of database with the value of the arguements.
- get_themes_list ==> gets all the names of themes available.
- get_site_logo ==> returns the url of the site logo.
- load_css ==> includes the css.php from the active theme.
- load_index ==> includes the index.php from the active theme.
- load_footer ==> includes the footer from the active theme.
0 comments:
Post a Comment