I have been working like crazy on my own website, and on a few others, while I love being super busy and making a little extra money, there are some things that I do not want to spend endless hours on because it would make my work earning $2/hr or less!

When you are making a website you usually have navigation links, and if you have about a dozen pages or more, if you change one line then you have to go through all your pages to change that one link.  Just imagine the work if a client wanted a link one way and you change it in a dozen pages, just to have that client change his or her mind a day later!

PHP to the rescue!

Instead of having your links written in HTML on each page

<ul class="left_ul">
 <li><a href="page_learnsoftware.php">Learning About Software </a></li>
 <li><a href="page_absolutebest.php">Being Our Absolute Best </a></li>
 <li><a href="page_writesomuch.php">Why Try to Write So Much?</a></li>
 <li><a href="page_androidappdev.php">Android App Development</a></li>
 <li><a href="page_exhaustiveresume.php">My Exhaustive Resume </a></li>
</ul>

You could have this as a separate file, something like “mainlinklist.php” and then have an include snippet in your content pages


<!-- buttons -->
<div id="buttons">
<ul>
<?php include("mainlinklist.php"); ?>
</ul>
</div>
<!-- content -->
<div id="content">

Your main link list file should have a php echo statement in it, here is my entire file for my link list…


<?php
 echo '
 <li><a href="page_learnsoftware.php">Learning About Software </a></li>
 <li><a href="page_absolutebest.php">Being Our Absolute Best </a></li>
 <li><a href="page_writesomuch.php">Why Try to Write So Much?</a></li>
 <li><a href="page_androidappdev.php">Android App Development</a></li>
 <li><a href="page_exhaustiveresume.php">My Exhaustive Resume </a></li>
 ';
?>

This will insert the code inside the echo statement into your webpage, now when you need to change a link across dozens of pages there will only be one place that you have to change that link!

Errata:

If there is something incorrect about how I did this OR you need or want more information on how this is done or other little gotchas please let me know and I will update this post.

Advertisements