Back when I first changed the format of my page so that I had the same list of links down the side of every page, I quickly discovered that it was a pain to have to go through 5 or 6 pages of HTML/PHP adding new links here and there.
I eventually came up with a system that makes it much easier to add/remove links from all my pages in a single go. On every page that has a list of links, I put this at the top:
include "path/to/linkage.inc";
The file linkage.inc contains a series of multidimensional arrays, like so:
$blogsLinkage = array(
0 => array("http://www.snazzykat.com/", "snazzykat"),
1 => array("http://www.scriptygoddess.com/", "Scriptygoddess"),
2 => array("http://www.technoerotica.net/", "technoerotica"),
4 => array("http://www.neuroticfishbowl.com/", "neurotic fishbowl"),
5 => array("http://www.tampatantrum.com/", "aint too proud to blog"),
7 => array("http://troll54.blogspot.com/", "Troll54"),
8 => array("http://timatollah.blogspot.com/", "Timatollah"),
9 => array("http://www.greasypants.org/", "greasypants"),
10 => array("http://www.randomramblings.com/", "Random Ramblings"),
);
$techLinkage = array(
0 => array("http://www.thinkgeek.com/", "ThinkGeek"),
1 => array("http://www.phpbuilder.com/", "PHP Builder"),
2 => array("http://www.scriptygoddess.com/", "scriptygoddess"),
3 => array("http://www.dynamicdrive.com/", "Dynamic Drive"),
);
Then, in each file where the links are to be listed, it's a simple matter of a nice little loop to render the code:
<?php
foreach ($blogsLinkage as $val) {
print "<a href=\"$val[0]\">$val[1]</a><br />";
}
?>
[more HTML code…]
<?php
foreach ($techLinkage as $val) {
print "<a href=\"$val[0]\">$val[1]</a><br />";
}
?>
Then, whenever I need to add a new link, I simply put a new entry into linkage.inc. If I need to remove a link, simply take it out of linkage.inc. This way, all the pages are updated automatically, and it's much easier!
Guest authored by:
Will – silverfisch.net