MikeFloutier Posted August 12, 2006 Share Posted August 12, 2006 Hi,I'm working on my very first site (for my wife) and it now consists of several pages all containing the same nav-bar menu. (the only exception being an indication of which page is currently visible).I'm finding it a little tedious that when ever I make an alteration to the nav-bar this means altering each page in turn by hand.Is there a way I can make a "standard" nav-bar that can be referred to and positioned in each page, (a sort of macro) but only exists once in long-hand?ThanksMike Link to comment Share on other sites More sharing options...
Moridin Posted August 12, 2006 Share Posted August 12, 2006 Yes, there is. You could use the PHP include or require function.- Moridin Link to comment Share on other sites More sharing options...
Chocolate570 Posted August 12, 2006 Share Posted August 12, 2006 Here's how to do what Moridin said.First, create a file called "navbar.php". Put the nav bar code in that file, and JUST the nav bar code. This is the file you will edit whenever you want to. Also, it doesn't have to be .php---it can be .html or whatever, but just to simplify this, keep it as .php.Next, rename all your other pages to .php, or .shtml---again, keep it.php to simplify this. Replace your nav bar code in all of the pages to:<?php include("navbar.php"); ?>After that, your pages should all display your navbar perfectly, and when you change navbar.php, they all will change. Hope that helps. Link to comment Share on other sites More sharing options...
Err Posted August 12, 2006 Share Posted August 12, 2006 Yup. You can use either PHP or another method that I can't remember right now.But I found out that using php is easier, at least in my case. You have to have php enabled for this work. The code: <?php include ("header.html"); ?> You have to make a page called "header.html" or whatever you want with the navgation bar html that you want it to repeat on all pages. Instead of putting your html where you would regularly put it for the naviagtion bar, replace it with the above code and it should display your html from the header.html page. Please keep in mind that you would most likely have to change all your pages to .php extensions if they're not already. Also you would have to go into all your pages and replace your html with the php code above... only once. Seems like a lot, but it pays off. I know.EDIT: Chocolate570 beat me too it... oh well. Link to comment Share on other sites More sharing options...
MikeFloutier Posted August 13, 2006 Author Share Posted August 13, 2006 Thanks guys,Looks like I need to start learning php too!MikePs At the moment I get each page to have it's relative nav-bar entry underlined when it's being displayed. Can this still be done using this .php method? Link to comment Share on other sites More sharing options...
Moridin Posted August 13, 2006 Share Posted August 13, 2006 I suppose you can use some variant of the if-else javascript script. <script type="text/javascript"><!--if( location.href == "That_page_where_you_want_it_underlined" ){document.write("<span style="text-decoration: underlined;">HTML for the normal link here</span>")}else{document.write("HTML for the normal link here")}//--></script>Customize to fit your needs.- Moridin Link to comment Share on other sites More sharing options...
justsomeguy Posted August 14, 2006 Share Posted August 14, 2006 If the server support Server-Side Includes (SSI), you can use that instead of using PHP. http://httpd.apache.org/docs/1.3/howto/ssi.html Link to comment Share on other sites More sharing options...
televirtual Posted August 25, 2006 Share Posted August 25, 2006 I'm having this issue as well but i can't get it to work with your suggestions.I've made a html doc called menu.html and just put the navigation bar code in it.Then i've made copy of my index for testing purposes and renamed it 'copy of index.php'Then i've replace the menu code with <?php include ("menu.html"); ?>But when i open copy of index.php with firefox the menu doesn't appear.....any ideas anyone? Link to comment Share on other sites More sharing options...
televirtual Posted August 25, 2006 Share Posted August 25, 2006 scrap my question, I just discovered thisNote: Coldfusion, ASP.NET, JSP or PHP are not currently supported on the BT Connect platform.so i guess that's why it doesn't work!looks like i'm going to have to try the ugly javascript solution!cheersGreg Link to comment Share on other sites More sharing options...
[Coyot3] Posted August 25, 2006 Share Posted August 25, 2006 maybe with JavaScript you can write a function that prints the menu and than you only have to call this function. function drawMenu(){ document.write("<a hre=\"page1.html\" target=\"_self\" title=\"go to page1\">page1</a>"); document.write("<a hre=\"page2.html\" target=\"_self\" title=\"go to page2\">page2</a>");} in every page include this at <head> section put this: <script src="xxx.js"></script> (I supose that you named your file xxx.js)Later, where you want to draw the menu you only have to do: <script type="text/javascript"> drawMenu();</script> By this way to will not need server side languages like PHP.Paulo A. Silva Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now