1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

One menu for all pages

Discussion in 'HTML & Website Design' started by kgrad, Jan 19, 2007.

Thread Status:
Not open for further replies.
  1. #1
    I have a business website, with all static html pages. There is a menu on all the pages.
    Now, I want to add an extra element in the menu, but it's really painful,:( to change each and every page that contains the menu.
    Can anyone please provide a solution to this kind of problem.
    Thanks.
    SEMrush
     
    kgrad, Jan 19, 2007 IP
    SEMrush
  2. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    434
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Fortunately you have a few options available to you. If your server supports server-side includes, you can write an include file (it's a simple text file) and then insert it into your Web pages via an include command.

    If your server has a server-side programming language like ASP or PHP installed and properly configured, you can use that as well.

    What's your server currently running?
     
    Dan Schulz, Jan 19, 2007 IP
  3. kgrad

    kgrad Well-Known Member

    Messages:
    2,414
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    130
    #3
    My server supports server-side inlcudes as well as PHP. Can you please give me an example of how to do it. Thanks.
     
    kgrad, Jan 19, 2007 IP
  4. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    434
    Best Answers:
    0
    Trophy Points:
    0
    #4
    Sure can.

    For server-side includes, (after creating your separate file), put this into your Web page:
    
    <!--#include virtual="/path/to/filename.ext"-->
    
    Code (markup):
    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:
    
    <?php include("filename.inc.php"); ?>
    
    Code (markup):
    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):
    
    <?php include($DOCUMENT_ROOT . "/includes/filename.inc.php"); ?>
    
    Code (markup):
    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 me.
     
    Dan Schulz, Jan 19, 2007 IP
  5. pr0xy122

    pr0xy122 Peon

    Messages:
    1,649
    Likes Received:
    21
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I would agree with Dan on this one, you have to make sure it is still organized.
     
    pr0xy122, Jan 19, 2007 IP
  6. Roman

    Roman Buffalo Tamerâ„¢

    Messages:
    6,217
    Likes Received:
    592
    Best Answers:
    0
    Trophy Points:
    260
    #6
    Or you could find a search and replace program and do this:

    Search for:
    <A HREF="last menu item">Link</A>

    Replace with:
    <A HREF="last menu item">Link</A><br>
    <A HREF="new menu item">New Link</A>

    There are many search & replace programs that will run through entire folders in seconds.
     
    Roman, Jan 19, 2007 IP
  7. kgrad

    kgrad Well-Known Member

    Messages:
    2,414
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    130
    #7
    Thanks a tonne for your help Dan!:eek:
    Probably this will solve my problem!:)
    Thanks once again, and,
    rep+ from my me:D
     
    kgrad, Jan 19, 2007 IP
  8. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    434
    Best Answers:
    0
    Trophy Points:
    0
    #8
    Yup. Organization is the key. Something that should be done before any Web design/re-design/development/re-development project even gets under way.

    Another thing, if your pages are saved using .html extensions yet you switch to another file type, be sure to do a 301 redirect on your pages so that the links are not broken. Not only will this help your human visitors (who may think your site is broken if you don't), but it will also help the search engines find your "new" pages.

    I'll let you take your pick of the Google search results for 301 redirect tutorials, since I don't know what your reading style is like:
    http://www.google.com/search?client=opera&rls=en&q=301+redirect&sourceid=opera&ie=utf-8&oe=utf-8
     
    Dan Schulz, Jan 19, 2007 IP
  9. my44

    my44 Peon

    Messages:
    722
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #9
    Dan Schulz (or other web gurus),

    Is there anyway I can put absolute URL in the SSI include? I've tried something like <#include virtual = "http://www.bla.net/nav-files/footer.htm" --> but it does not work.

    Would have been easier if it does since getting relative URLs from different subfolders can be cumbersome.
     
    my44, Feb 12, 2007 IP
  10. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    434
    Best Answers:
    0
    Trophy Points:
    0
    #10
    You'll have to change virtual to file if you want to do that.

    But frankly I don't see why you would even want to specify an absolute URL like that anyway.
     
    Dan Schulz, Feb 12, 2007 IP
    my44 likes this.
  11. my44

    my44 Peon

    Messages:
    722
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #11
    Oh really? Thanks!

    Main reason: I want to have only one header.htm file from which ALL pages from different folders will point to the absolute URL of the header.htm

    With #include virtual, I have to change the relative paths in different (sub)folders, eg:

    folder#1 - "include virtual ="nav/header.htm"
    L_subfolder#1.1 - "include virtual ="../nav/header.htm"
    L__subfolder#1.1.1 - - "include virtual ="../../nav/header.htm"

    It goes a bit ugly when the number of shtml pages grow and grow.
     
    my44, Feb 12, 2007 IP
  12. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    434
    Best Answers:
    0
    Trophy Points:
    0
    #12
    So why not reference it this way?

    /includes/included-file.html
     
    Dan Schulz, Feb 12, 2007 IP
  13. my44

    my44 Peon

    Messages:
    722
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #13
    Where do I put it? In .htaccess file? Can you be more specific by way of an example? I put all my navigation files (header.htm, sidebar.htm, footer.htm) in a folder called "nav"
     
    my44, Feb 12, 2007 IP
  14. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    434
    Best Answers:
    0
    Trophy Points:
    0
    #14
    Nav, includes, doesn't matter, really. It's just a folder, afterall.
     
    Dan Schulz, Feb 12, 2007 IP
  15. my44

    my44 Peon

    Messages:
    722
    Likes Received:
    24
    Best Answers:
    0
    Trophy Points:
    0
    #15
    I mean "/includes/included-file.html" will only work with .shtml files in the directory immediately higher up from folder "includes". But for subfolders, putting "/includes/included-file.html" means the .shtml cannot find the "includes" folder.
     
    my44, Feb 12, 2007 IP
  16. duilen

    duilen Active Member

    Messages:
    354
    Likes Received:
    10
    Best Answers:
    0
    Trophy Points:
    58
    #16
    This method would be a huge pain. You would need to do the find and replace every time you want to change a sitewide element. You also need to publish every file when you do this. This could make a 20 second change take 10 minutes or longer on a large site.

    You would also run into problems with relative links. If you have an element that is used in different folders some links may have ../linkpath.html others may have /linkpath.html as opposed to linkpath.html. This would cause your find and replace to miss a lot of the instances. You could get around this with complex regex searches but that would take much longer.
     
    duilen, Jun 2, 2007 IP
    kgrad likes this.
  17. jgjg

    jgjg Peon

    Messages:
    595
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    0
    #17
    if you don't want to rename your webpages as .shtml you can change your .htaccess file to look like this:

    Options Includes
    AddType text/html .html
    AddHandler server-parsed .html
    AddHandler server-parsed .htm


    and then just use something like:

    <!--#include file="topnavigation.html" -->

    I've used this method on dozens of sites, works fine unless in rare case of certain server configurations but works maybe on 9 out of 10 unix/linux servers I've tried.

    Let me know if it works for you.
     
    jgjg, Jun 4, 2007 IP
    kgrad likes this.
  18. kgrad

    kgrad Well-Known Member

    Messages:
    2,414
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    130
    #18
    I appreciate the your help guys.
    The problem is now solved. :D (Check the age of this thread.:))
     
    kgrad, Jun 4, 2007 IP
  19. Dan Schulz

    Dan Schulz Peon

    Messages:
    6,032
    Likes Received:
    434
    Best Answers:
    0
    Trophy Points:
    0
    #19
    I forgot to mention using .htaccess in this manner when I wrote my post on this thread. Sorry about that. :(
     
    Dan Schulz, Jun 4, 2007 IP
    kgrad likes this.
  20. kgrad

    kgrad Well-Known Member

    Messages:
    2,414
    Likes Received:
    82
    Best Answers:
    0
    Trophy Points:
    130
    #20
    Thanks for remembering.
    Rep+ to you and all who posted in this thread. :)
     
    kgrad, Jun 4, 2007 IP
Thread Status:
Not open for further replies.