Help - Search - Members - Calendar
Full Version: Navbar repetition
HTMLHelp Forums > Web Authoring > Markup (HTML, XHTML, XML)
GaryE
My website is http://bostontechnicalwriter.x10host.com/

My navbar section is exactly the same in my index page and each of my subject pages (Blogging: Electronic Products Magazine, IEEE Globalspec, etc, etc.)

Right now, if I want to add or delete one of the subject pages, I have to modify the navbar not only on the index page, but in each of the dozen or so subject pages. This is a cumbersome, error prone task. Is there any way to write only one navbar, and have it apply to the index page and all the subject pages?

BTW: Are "Navbar" and "subject Pages" the correct words?
CharlesEF
You can define your menu once, then 'include' it using a server side language. What languages does your host support? (PHP, ASP or ?)
GaryE
Hi Charles,

I use x10hosting, and at:

https://x10hosting.com/hosting-features

it says:

Complete Control

Want to write your own PHP scripts
or install a third-party package?
Sure!

So I guess that means I have free access to pHp

- Gary



CharlesEF
Ok, so you have PHP to use. The first thing to know is that any page that contains PHP code needs to have a '.php' extension and must be served up thru a web server. In theory, you could change the '.php' requirement by changing your web server configuration. I stay out of that part.

Next, create your menu page (save it as 'menu.html', for example). Only include the menu parts, do not include <head> or <body> or any other parts.

Now, on each page that will have the menu you need to add something like this:
CODE
<nav id="menu">
  <?php include("{$_SERVER['DOCUMENT_ROOT']}/path/to/menu.html");?>
</nav>
These are the pages that will need the '.php' extension. The <nav> is valid for HTML5 pages. If you are using anything else then use a <div> instead.

That is the basics of what you need to do. If you need to work on the position or something else then you need to use CSS.
GaryE
Hi Charles,

I'll give this a try.

Thanks!
Gary
GaryE
Hi Charles,

Your idea worked. I tried it out on a new free host, the modified website is:
https://exper17.000webhostapp.com/


I Inserted this command into each page:


<!-- Left Column, Navbar division -->
<?phpinclude('navbar.php');
<!-- End of Left Column, Navbar division -->


as for navbar.php itself
(after I took out most of the menu choices to save space in this note, they are all about the same):

<!-- Left Column, Navbar division -->
<div id="left_col">

<table style= "width: 100%" cellspacing="8" cellpadding="2">

<tr style="background-color: #ffcc33;">
<td style="width: 100%"><a href="index.php">Home</a></td>
</tr>

<tr style="background-color: #ffcc33;">
<td style="width: 100%"><a href="softwarewriter.php">Software Articles</a></td>
</tr>

<tr style="background-color: #ffcc33;">
<td style="width: 100%"><a href="scopejunction.php">Scope Junction</a></td>
</tr>


<tr style="background-color: #ffcc33;">
<td style="width: 100%"><a href="gmvolt.php">GM Volt</a></td>
</tr>
</table>
</div><!-- End of Left Column, Navbar division -->


Now, I only have to modify "navbar" in one place only when I want to change my choices. So, thanks again for your help!


Regards,
Gary
CharlesEF
Great, glad it worked out for you. One thing I did see that needs fixing, maybe if was just a copy and paste error. This line of code:
CODE
<?phpinclude('navbar.php');
Should be:
CODE
<?php include('navbar.php');?>
In PHP you need '<?php' to start PHP code and '?>' to end PHP code.

Also you could expand this method to include your header or footer sections (if you use either).
This is a "lo-fi" version of our main content. To view the full version with more information, formatting and images, please click here.
Invision Power Board © 2001-2024 Invision Power Services, Inc.