This PHP script exists soley so that I don't have to change dozens of pages whenever I change the location of a page, or remove it from my website. It reads the internal links in from a MySQL database (soon to be converted to use the PEAR framework), and lists the links by category wherever you call the function from.
I know this code is somewhat sloppy, but it's a first attempt at PHP so... comment away.
Also I have a css entry for my menu items set up, hence the class="menu".
Take a look at http://www.DanielGrantTaylor.com for a short view of this code in action. It creates the menu at the bottom of every page.
By : mulciber316
<?php
function printconstantlinks()
{
// Variables:
$lastcategory = FALSE; // The last link category seen. Cheat a bit here to say if we've seen a link category yet.
$serverlocation = "localhost";
$username = "mywebsiteusername";
$password = "mywebsiteuserpassword";
$db_name = "mywebsitedatabase";
// Now we want to display all the links we want on every page,
// Get a connection to the database first.
$conn = mysql_connect($serverlocation, $username, $password)
or die("Could Not Connect To Server");
mysql_select_db($db_name) or die("Could not use database for website");
// Now, we want to order our links by their category, and then their caption.
$query = "SELECT link_type, link_caption, link_location FROM internal_links ORDER BY link_type, link_caption";
$result = mysql_query($query) or die("Query failed.");
print "<p class=\"menu\">";
while ($line = mysql_fetch_array($result, MYSQL_ASSOC))
{
extract($line);
if ($lastcategory != $link_type)
{
if ($lastcategory)
print "<br />\n";
if ($link_type != "Navigation")
print "$link_type: ";
else
print " ";
$lastcategory = $link_type;
}
if ($link_caption != "")
{
print " [ ";
for ($i = (15 - strlen($link_caption)) / 2; $i > 0; $i = $i - 1)
{
print " ";
}
print "<a href='$link_location' class='menu'>";
print "$link_caption</a>";
for ($i = (15 - strlen($link_caption)) / 2; $i > 0; $i = $i - 1)
{
print " ";
}
if ((15-strlen($link_caption)) % 2 == 0)
print " ";
}
else
{
print " [ ";
print "<a href='$link_location' class='menu'>";
print "$link_location</a>";
}
print "</a> ]";
}
print "<br /></p>\n";
mysql_free_result($result);
mysql_close($conn);
}
?>
///////////////////////////////////////////////
#MySQL syntax to create internal_links table:
CREATE TABLE internal_links (
_handle INT(11) NOT NULL AUTO_INCREMENT PRIMARY KEY,
link_caption TEXT,
link_location TEXT NOT NULL,
link_type ENUM("Business", "Personal", "Projects", "Scholastic", "Navigation")
);
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |
More Site Navigation Code Articles
More By Codewalkers
developerWorks - FREE Tools! |
Hear how IBM Rational Project and Portfolio Management integrated solutions help teams put the right tools and processes in place to maximize the effectiveness and efficiency of project teams and ensure that the business vision is being executed correctly. Learn how to automate and integrate requirements prioritization, top-down project planning, communications and controls, and methodology deployment to keep your scope, costs, and schedules under control. Tackle with an end-to-end approach the management of scope and scope changes, usage of methodology to control and empower project teams, and optimization of resources to align activity costs with the overall project plan. FREE! Go There Now!
|
|
|
|
Poor Requirements Management capabilities in an Enterprise have been linked to excessive project failures, escalating IT costs, and failure to deliver competitive advantage into the marketplace. Join Brianna M Smith from IBM Rational and learn about how successful organizations align IT and Business stakeholders through collaborative processes and tools for effective requirements management, and how an integrated approach across the IT lifecycle can provide unparalleled visibility and traceability to ensure that project teams are delivering on the business vision by "doing the right things" and "doing things right." FREE! Go There Now!
|
|
|
|
Build secure Web services with transport-level security using IBM Rational Application Developer V7 and IBM WebSphere Application Server V6.1. Follow this three-part series for step-by-step instructions about how to develop Web services and clients, configure HTTP basic authentication, and configure HTTP over SSL (HTTPS). This first part of the series walks you through building a Web service for a simple calculator application. You generate and test two different types of Web services clients: a Java Platform, Enterprise Edition (Java EE) client and a stand-alone Java client. You also handle user-defined exceptions in Web services. FREE! Go There Now!
|
|
|
|
Visit IBM developerWorks to download a free trial version of Lotus Quickr 8.0, which enables collaboration by transforming the way everyday business content such as documents, rich media, photos, and video can be shared. Lotus Quickr makes it faster and easier to share content of all types (not just documents) within virtual teams. It is designed to make it easier to collaborate across organizational boundaries, while continuing to work within the context of familiar desktop applications. FREE! Go There Now!
|
|
|
|
Learn from the best! Find out how developers use Rational ClearCase to be more flexible, innovative and deliver higher quality code in the Rational ClearCase Power Users eKit. This complimentary eKit provides a collection of materials, like articles, whitepapers, and demos that can help you become a power user of Rational ClearCase. FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 4 at 1:00 pm ET to discuss how Rational Method Composer can help meet your compliance objectives. Get your questions answered! FREE! Go There Now!
|
|
|
|
Join this Rational Talks to You teleconference on December 6 at 1:00 pm ET to participate in an agile application development discussion and get your questions answered on using IBM Rational Method Composer in a distributed environment.Get your questions answered! FREE! Go There Now!
|
|
|
|
This paper is about the critical role that a discipline called integrated requirements management can play in helping to ensure that your business goals and IT investments are continuously aligned—whether you are sourcing, integrating, building or maintaining software. It also looks at ways that automated IBM Rational® products can work together to help you use requirements in the very best way. FREE! Go There Now!
|
|
|
|
Get a free trial download of the latest version of IBM Rational Tester for SOA Quality V7.0.1, a functional and regression testing tool that enables the creation, comprehension, modification and execution of testing GUI-less Web services. FREE! Go There Now!
|
|
|
|
User communities play an important role in communication and collaboration around products, solutions and other areas of special interest to members. Successful communities are able to provide the right mix of content and services to deliver a value proposition that resonates with each audience. Join Tom Inman, VP of Marketing for Information and Platform Solutions as he introduces the new LeverageINFORMATION community. During this webcast, learn about the value provided by the community and how customers and partners derive value from the community in addressing their own technical and business challenges. FREE! Go There Now!
|
|
|
|
All FREE IBM® developerWorks Tools! |