Jump to content

Nav-Bar Menu section


MikeFloutier

Recommended Posts

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

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

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

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

  • 2 weeks later...

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

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

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
×
×
  • Create New...