Easy Menus with PHP, Part 1

When I was first starting out in Web design, I quickly learned that updating your site’s menus can become a major chore rather quickly. Since I liked to hard-code everything, I only knew a couple main options, neither of which were great:

  1. Update every page manually: This works out for a while, but when you get a dozen or more pages, it starts to break down. Besides the fact that it’s time-consuming, you’re prone to errors, which can lead to dead links or orphaned pages. There’s gotta’ be a better way…
  2. Use frames: Though this technique looked promising to begin with, it has many drawbacks:
    • You can’t bookmark a page inside a frame. The only page a user can bookmark, is the main homepage — the first framed page they come to. That means that if you’re studying the green-crested striped Moldavian iguana at the Iguanapedia website, and the page is inside a frame, you’ll be stuck with adding the main page to your favorites. Then you have to drill down to the inner page every time you arrive. No fun.
    • Search engines and others can’t read frames properly. Here’s what a Google helpfile on frames says:

Google supports frames and iframes to the extent that it can. Frames can cause problems for search engines because they don’t correspond to the conceptual model of the web. In this model, one page displays only one URL. Pages that use frames or iframes display several URLs (one for each frame) within a single page…

[You may use] the “NoFrames” tag to provide alternate content. If you [don’t,] … then you’ll exclude both search engines and individuals who’ve disabled [or can’t use] frames on their browsers.

In other words, frames seem cool, but search engines and frames-disabled browsers don’t like them. You’ll get partial support at best. If you take the time to make alternative content for them, you’re basically recreating your site — canceling out the time savings you wanted the frames to give you in the first place!

Easy Menus with PHP Includes
What’s a Web-coder to do? Lo and behold, the answer comes from PHP programming, and PHP includes specifically. Now you can do one of three things:

  • PHP Elephant

    Image by Laughing Squid via Flickr

    For you DIY types, go check out the PHP.net description here. Just plug in the PHP inside your HTML code.

  • If you’re a managerial type who doesn’t want to get his hands dirty with all this, forward this post to your resident Webmaster. (You do have one, right?)
  • If you want a bit more hand-holding, come back tomorrow for a tutorial. See you soon!

Leave a Reply

Your email address will not be published. Required fields are marked *