Go Back   CodingForums.com > :: Client side development > HTML & CSS

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 02-16-2011, 04:06 PM   PM User | #1
sophshep
New Coder

 
Join Date: Nov 2008
Posts: 33
Thanks: 5
Thanked 0 Times in 0 Posts
sophshep is an unknown quantity at this point
Question Making a single html file for my Nav (php?)

This might be a php question, I'm not really sure because I am somewhat new to development.

I am building a site that has a large and detailed navigation, with lots of subpages. I imagine that over time, I will be adding and deleting some pages, and will also need to make the corresponding change in my <ul> nav.

As it is set up now, I'll need to open 20 different pages and edit each of their code. I can see this getting very tedious, confusing, and having a large likelihood that I'll mess something up accidentally.

My question is: Is there a way of having my Header (and nav) as one single html or php file? So that I can only edit that one file, and it will change on all pages of my site (similar to editing a CSS style sheet). I am almost certain I have seen this done on Wordpress themes.

Sorry if this is a stupid question! If someone could just point me in the direction of a tutorial or tell me what this is called, that would be great.

Thank you!!

Sophie
sophshep is offline   Reply With Quote
Old 02-16-2011, 04:35 PM   PM User | #2
Excavator
Master Coder


 
Excavator's Avatar
 
Join Date: Dec 2006
Location: Alaska
Posts: 9,410
Thanks: 22
Thanked 1,765 Times in 1,749 Posts
Excavator has a spectacular aura aboutExcavator has a spectacular aura aboutExcavator has a spectacular aura about
Good morning sophshep,
A server side include can do what you're wanting. You can edit the one file and any of your pages that have the include would reflect that edited file.
Very handy.

Have a look at a PHP Include Tutorial here.
__________________
Validate often DURING development - Use it like a splelchecker | Debug during Development |Write it for FireFox, ignore IE
Use the right DocType | Validate your markup | Validate your CSS | Why validating is good | Why tables are bad
Excavator is offline   Reply With Quote
The Following 2 Users Say Thank You to Excavator For This Useful Post:
marilynn.fowler (02-16-2011), sophshep (02-16-2011)
Old 02-16-2011, 04:36 PM   PM User | #3
abduraooft
Supreme Master coder!

 
abduraooft's Avatar
 
Join Date: Mar 2007
Location: N/A
Posts: 14,680
Thanks: 158
Thanked 2,182 Times in 2,169 Posts
abduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really niceabduraooft is just really nice
Quote:
My question is: Is there a way of having my Header (and nav) as one single html or php file?
Yes there is! Just make separate files to save the html markup (shouldn't be a complte document, just the only relevant <div>s or <ul>-<li>s ) of your header and nav. Then use include() statements to include them, wherever required.
__________________
Quote:
The Dream is not what you see in sleep; Dream is the thing which doesn't let you sleep. --(Dr. APJ. Abdul Kalam)
abduraooft is offline   Reply With Quote
Users who have thanked abduraooft for this post:
sophshep (02-16-2011)
Old 02-16-2011, 04:37 PM   PM User | #4
sophshep
New Coder

 
Join Date: Nov 2008
Posts: 33
Thanks: 5
Thanked 0 Times in 0 Posts
sophshep is an unknown quantity at this point
Excavator saves the day! AGAIN!!!
sophshep is offline   Reply With Quote
Old 02-16-2011, 04:46 PM   PM User | #5
yorkcoparamedic
New to the CF scene

 
Join Date: Feb 2011
Posts: 4
Thanks: 1
Thanked 0 Times in 0 Posts
yorkcoparamedic is an unknown quantity at this point
It is sort of a PHP and XHTML question. So here is how you can go about it. Create your pages with the following format or comparable. The following would be index.php
Code:
<?php include("header.inc"); ?>
<body>

<div id="nav">
<?php include("nav.inc"); ?>
</div>

</body>
<?php include("footer.inc"); ?>
Save your header file as .inc
Code:
<html>
<head>
<title></title>
</head>
Your footer file as .inc
Code:
</html>
Then save your navigation XHTML in the following nav.inc. All should work out for you. If you need more help just ask. All of your pages must be renamed to end with .php or this will not work.
yorkcoparamedic is offline   Reply With Quote
Reply

Bookmarks

Tags
nav, php

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 08:21 PM.


Advertisement
Log in to turn off these ads.