Results 1 to 7 of 7

Thread: Common Menu and Headers?

  1. #1
    Registered cpc's Avatar
    Join Date
    Jul 2007
    Location
    San Francisco
    Posts
    13

    Common Menu and Headers?

    Hi all,

    What do most people do for common menus and header links? I'm creating a new site and find myself constantly changing the menu content as I learn more about SEO (thanks to this site).

    Right now, my site is straight HTML with CSS (original template from oswd). My understanding is that is best to have your menus on each page but this it is fairly tedious to update all my pages for each tweak. Of course, I probably should have just designed the menus first. Still, I think I may be missing something obvious. Thanks.

    --CPC

  2. #2
    Registered
    Join Date
    Mar 2006
    Posts
    156
    What's usually done is to put the Menu (or Footer or Header) in one place and include it in all the pages. That way, when you want to make a change, you only have to change it in one place.

    A very common way of doing this is using PHP and including your Menu file into all the pages on your site. So you can put your menu in a file named "menu.inc.php" and then when you want to show your menu in a page, you just include it like this: <?php include 'menu.inc.php'; ?>

    But of course all your pages must use the .php extension in order to do it that way. You have other ways of doing it without PHP, but this is one of the better ones in my opinion.

  3. #3
    Administrator Chris's Avatar
    Join Date
    Feb 2003
    Location
    East Lansing, MI USA
    Posts
    7,055
    The other way is with SSI, server side includes. Searching Google should find you an amiable tutorial.
    Chris Beasley - My Guide to Building a Successful Website[size=1]
    Content Sites: ABCDFGHIJKLMNOP|Forums: ABCD EF|Ecommerce: Swords Knives

  4. #4
    Quahog's Most Wanted Dan Schulz's Avatar
    Join Date
    Feb 2007
    Location
    Aurora, Illinois
    Posts
    91
    Or read this post. I posted this last year on Digital Point's forums (I really need to centralize everything). I'm going to provide the link to the post at the end of this one.


    For server-side includes, (after creating your separate file), put this into your Web page:
    Code:
    <!--#include virtual="/path/to/filename.ext"-->
    where /path/to/filename.ext is the path to your included file (such as menu.html) relative to the document root (the folder where your Web pages go, usually public_html or www) and .ext is the extension of the file (.html for example). I personally prefer to put all my include files into a single folder, directly below the root (again, usually public_html or www), called includes.

    For example, the path would be /includes/menu.html

    You would then save the Web page as a .shtml file (or configure Apache to parse .html as .shtml files so you can just keep the .html extension, but I'm not comfortable enough with Apache to do this).

    As for PHP, create your included file as normal, then follow the same instructions above, but use this code instead:
    Code:
    <?php include("filename.inc.php"); ?>
    Of course, if you're using multiple folders, you'll have a problem referencing your includes, even if you put them into a separate includes folder.

    For that, I usually do this (even though I should know better):
    Code:
    <?php include($DOCUMENT_ROOT . "/includes/filename.inc.php"); ?>
    Notice how in each case I declared the file extension to be .inc.php ? That's because the .inc is to remind me that it's an include page, and the .php is to force the server to parse it before sending it to the browser. If you have any sensitive data (like database login information) this becomes critical, since any schmuck could go to yoursite.com/includes/filename.inc (let's just say that filename.inc is database.inc for a second) and get the database login information if you don't put .php at the very end.

    And of course, rather than saving your Web page (with the include statements) as .html, you would save them as .php unless you configured the server to treat .html files the same as .php files.

    Hope that helps. If you need more, just ask.

    [Original Post: One Menu For All Pages]

    Something I forgot to mention in the original post. If you're using PHP, and you're calling sensitive data, like database queries, then put your includes folder outside of your root so that it's inaccessible to anyone who may be snooping around looking for an easy way to compromise your site's security. You'll have to modify the path to do this though.
    Last edited by Dan Schulz; 07-17-2007 at 01:48 PM.
    "Far away in cyberspace are my highest aspirations. I may not reach them, but I can envision their beauty, believe in them, and try to follow where they lead me."
    —Anonymous

  5. #5
    Registered cpc's Avatar
    Join Date
    Jul 2007
    Location
    San Francisco
    Posts
    13
    Great, thanks for the responses. I can setup a local apache to try SSI and will probably also try PHP (after I learn it

  6. #6
    Registered cpc's Avatar
    Join Date
    Jul 2007
    Location
    San Francisco
    Posts
    13
    One quick followup question. In PHP, is there a nice way generate the dynamic absolute domain for all your links?

    For example, if my site is www.foo.com, I prefer to use absolute paths (http://www.foo.com/somepage.php) instead of relative paths. I know I can use the $_SERVER['HTTP_HOST'] to prepend but that is very clunky.

    Or do most of you just hardcode your domain in and edit your hosts file to point to you local development server?

    Thanks!

  7. #7
    Quahog's Most Wanted Dan Schulz's Avatar
    Join Date
    Feb 2007
    Location
    Aurora, Illinois
    Posts
    91
    I just develop locally using relative link paths and the <base> element in the HEAD section of my Web pages on my local server, then remove the BASE element from the code when moving it over to the server (no need to change the link paths) since they'll point to the Web root anyway).
    "Far away in cyberspace are my highest aspirations. I may not reach them, but I can envision their beauty, believe in them, and try to follow where they lead me."
    —Anonymous

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •