[Simplog-devel] modular approach to customizing appearance and behavior
Brought to you by:
f-bomb
From: Jim Hu <ji...@ta...> - 2004-08-29 07:42:21
|
To make customizing the appearance and behavior of different blogs easier (at least for me), I broke up the index.php and header.php files so that they would call different layout options that I'm keeping in a subdirectory called layout. The new index.php is just: ------------------------------------------------------------------------ ---- <?php if(!file_exists("config.php")) { header("Location: install.php"); exit(0); } session_start(); require_once("lib.php"); require_once("class.BlogInfo.php"); require_once("class.BlogEntry.php"); $blogid = $_GET['blogid']; if(!isset($blogid)) { $blogid = 1; #set default blog to see } $blogInfo = new BlogInfo($blogid); include("header.php"); $testindexfile = "layout/index".$blogid.".php"; if (file_exists($testindexfile)){ $indexfile = $testindexfile; }else{ $indexfile = "layout/index0.php"; } include($indexfile); ?> ------------------------------------------------------------------------ ---- The new header.php file is reduced to: <?php header("X-Pingback: $baseurl/api.php\n"); if(!isset($blogInfo)) { $btitle = "Simplog"; } else { $btitle = $blogInfo->getBlogTitle(); $btag = $blogInfo->getBlogTagline(); } if(isLoggedIn()) { $uid = getUID($_SESSION['login']); } $testheaderfile = "layout/header".$blogid.".php"; if (file_exists($testheaderfile)){ $headerfile = $testheaderfile; }else{ $headerfile = "layout/header0.php"; } include($headerfile); if(isLoggedIn()) { show_menu(); } ?> <br> ------------------------------------------------------------------------ ---- inside the layout subdirectory I have a series of files named header0, header1, header11 etc, and index0, index1.... plus the css files. Only header0 and index0 are necessary layout/header0.php is the missing pieces of the original header.php: ------------------------------------------------------------------------ ---- <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1"> <title><?=$btitle?>: <?=$btag?></title> <script language="javascript" type="text/javascript" src="<?=$baseurl?>/simplog.js"></script> <link rel="alternate" type="text/xml" title="RSS" href="<?=$baseurl?>/rss2.php" /> <link rel="pingback" href="<?=$baseurl?>/api.php" /> <link rel="stylesheet" href="<?=$baseurl?>/layout/simplog.css" type="text/css" /> </head> <body bgcolor=#ffffff marginwidth=0 marginheight=0 leftmargin=0 topmargin=0> <table width=100% border=0 cellspacing=0 cellpadding=5 class=header> <tr> <td align=left><span class=blogname><?=$btitle?></span><br><span class=blogtag><?=$btag?></span></td> </tr> </table> ------------------------------------------------------------------------ ---- The alternate headers are customized to modify appearance (I specify which css to use in each one, so some blogs can share css files), plus to make a blog require user login (which I want for all the blogs I'm using to control other websites), I add <?php if(!isLoggedIn()) { auth(); } ?> to the header. This also makes the headers look different for all the views of the blog - archives, search results, edit pages etc. layout/index0.php is just the missing pieces of the original index.php: ------------------------------------------------------------------------ ---- <table cellpadding=0 cellspacing=0 border=0 width="100%" style="height:90%;"> <tr valign="top"> <td style="border-right:1px solid #999999;padding-right:24px;"> <div style="padding:10px;"> <?php @include("$baseurl/blog.php?blogid=$blogid"); ?> </div> </td> <td align="center" width=150 style="padding-left: 24px;"> <?php include("blocks.php"); ?> </td> </tr> </table> </body> </html> ------------------------------------------------------------------------ ---- Obviously, this allows me to alter the appearance of the individual blog pages, put blocks on the left, add other stuff etc. To a naive user, one could just install and use the defaults. Changing the appearance of different blogs and staying within that look and feel is easier for the slightly more sophisticated user with this approach than by feeding blog content to another page, as internal navigation links don't have to be adjusted at all. Would this be worth including in the next version? Jim |