Greetings,
More often these day's I am noticing that themers are coding buttons and links directly into the theme - it's nice to see because the generic menu is soooooo boring! The trouble is this can be a nightmare to update if you are not familiar with
HTML or
PHP or whatever.
The issue is addressed somewhat with top and bottom links defined in the lang file of some of the core themes, but this is not good enough - what if you want to add more?
My solution to this is to dynamically build the links (or link menu) using an array. Enough rambling let's do it.
Create a file called themes/yourtheme/lang/eng/linkConfig.php and include the folowing code:
<?php//Items for menu buttons in header - add new lines when required.$topnav =
array ("Home" =>
"index.php",
"Articles" =>
"modules.php?op=modload&name=Topics&file=index",
"Sections" =>
"modules.php?op=modload&name=Sections&file=index",
"Downloads"=>
"modules.php?op=modload&name=Downloads&file=index",
"Forum" =>
"modules.php?op=modload&name=XForum&file=index",
"FAQ" =>
"modules.php?op=modload&name=FAQ&file=index" //remember there is no comma on the last line!!!);
?>
This is the config file and you can add more links as required because the "while loop" will include them all .
You add the following code to your theme.php file (or what ever template you want it to display on)
<?php//Link builder by Lobos//Don't touch this code! Edit linkConfig.php in the lang folder :)// Get the langauge variable and include the correct array $currentlang = pnUserGetLang
();
include $themepath.
"lang/".
$currentlang.
"/linkConfig.php";
while (list ($key,
$value) =
each ($topnav)) echo"<a href=\"" .
$value .
"\">" .
$key .
"</a> |  \n";
?>
See how the $key and $value variables are taken from the file in the lang folder.
This is a very basic way of doing this and will make for a very boring menu... good for footer links though. The code will render like this:
<a href="index.php">Home</a> | 
<a href="modules.php?op=modload&name=Topics&file=index">Articles</a> | 
And so on and so on
Like I was saying this is very boring so below I have included the loop I use to build the button menu in my latest theme wvCorporateX:
<?php//Link builder by Lobos//Don't touch this code! Edit linkConfig.php in the lang folder :)$currentlang = pnUserGetLang
();
include $themepath.
"lang/".
$currentlang.
"/navbar.php";
while (list ($key,
$value) =
each ($topnav)) echo"<td style=\"padding-left: 0px; padding-bottom: 0px; padding-top: 6px; background-image:url($imgpath/wvButton.jpg);\" width=\"92\" align=\"center\" height=\"28\" valign=\"middle\"> \n" .
"<font class=\"wvMCblockTitle\"><a href=\"" .
$value .
"\">" .
$key .
"</a></font></td> \n";
?>
A lot more complex and layout breakage could occur with too many links, but you should get the idea of the potential of this tasty bit of code. You can add as many of these as you want all you have to change is the "each variable" eg:
while (list ($key,
$value) =
each ($topnav))
to
while (list ($key,
$value) =
each ($bottomnav))
and in the linkConfig.php change
to
It is now easy (or fairly easy) for people with no html/php knowledge to update there theme links. You can do a lot with this: I used it to make the popup menus at webvida.com very easy to update and now I don't need to wade through heeps of javascript when I want to change things!
Kindest regards
Lobos
--
-Lobos
Professional PHP Framework Services: Concept, Development and Deployment