How to put your menu/static info. on every page

This is a discussion on "How to put your menu/static info. on every page" within the Starting Out section. This forum, and the thread "How to put your menu/static info. on every page are both part of the Design Your Website category.


 Subscribe in a reader

Go Back   Webforumz.com > Main Forums > Design Your Website > Starting Out

Notices




Reply
 
LinkBack Thread Tools
  #1  
Old Feb 21st, 2007, 23:24
Junior Member
Join Date: May 2006
Location: UK
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Question How to put your menu/static info. on every page

Hi

I'm still hand coding all my menus/static info. (e.g. logo) onto every page as it's the only way I know how to do it, but if I want to add one thing to the menus then I have to change 20 pages!


There must be a better way to do this. Please help.

Thanks
L
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote

  #2  
Old Feb 22nd, 2007, 00:30
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

Yes ... there is a better way and they are called includes. If your server supports PHP, I suggest you use that. Here the info for the include() function in PHP. You really don't need to know anything about php to use it and it's easy as pie.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #3  
Old Feb 22nd, 2007, 01:58
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

menu.html:
Code: Select all
<h1>Navigation</h1>
<ul>
    <li>Home</li>
    <li>Contact</li>
</ul>
your_page.php:
Code: Select all
<html>
    <head>
        <title>page</title>
    </head>
    <body>
        <p>Welcome to our site</p>
<?php
include "menu.html";
?>
        <p>Copyright &copy; 2007</p>
    </body>
</html>
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #4  
Old Feb 22nd, 2007, 03:22
Up'n'Coming Member
Join Date: Feb 2007
Location: United States
Age: 15
Posts: 79
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

Or you could just use a template if you for some reason can't or don't want to use PHP.
__________________
Daniel Thompson
danielwthompson.com
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #5  
Old Feb 22nd, 2007, 03:47
Elite Veteran
Join Date: Dec 2005
Location: On Internet
Posts: 4,859
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

But the included is the best and easiest way to accomplish this effect...Almost every one of my websites use the included feature...it is GREAT!!
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #6  
Old Mar 1st, 2007, 13:52
Junior Member
Join Date: May 2006
Location: UK
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

Thanks for all your info. guys.

Ryan - I've been playing around & I've got my index page to work following your model. I set up 2 pages - menu.html & index1.php, but to get it to work I had to strip out all the xthml guff that you nomally have to start the page with out of both pages i.e. the .html page & the .php page. Is this right? Does this mean you cannot get the pages verified on the WWW Consortium website?

Also, does it mean that all the pages (other than menu.html) for the website would become .php pages rather than .html pages? Does this pose any potential problems at all?

Hope you don't mind me asking as I don't fully understand the implications & I don't want to change all my pages then hit a potential problem!

Thanks a lot
Lynn
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #7  
Old Mar 1st, 2007, 13:59
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

Quote:
Originally Posted by lmc148 View Post
but to get it to work I had to strip out all the xthml guff that you nomally have to start the page with out of both pages i.e. the .html page & the .php page. Is this right?
Yes ... just like Ryan posted.

Quote:
Originally Posted by lmc148 View Post
Does this mean you cannot get the pages verified on the WWW Consortium website?
No ... look at the source of you index.php file ... everything is in there. PHP gets parsed by the server so when comes time to view the page everything assembled together and nobody know the difference.

Quote:
Originally Posted by lmc148 View Post
Also, does it mean that all the pages (other than menu.html) for the website would become .php pages rather than .html pages? Does this pose any potential problems at all?
All the page need to have the .php extension yes. No problems at all ... I use that method all the time.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #8  
Old Mar 1st, 2007, 23:01
Junior Member
Join Date: May 2006
Location: UK
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

Thanks Karinne.

I understand that using php/include looks seamless to the user & I've got a page working & checked it out for myself - it's great! I can see how it's so much better & easier to code this way & will save me loads of time (once I've gone through & converted all my pages that is :-O )

Just one thing though, I don't understand your reply to "Does this mean you cannot get the pages verified on the WWW Consortium website?"

When I did my xhtml course our tutor said we should make sure our code was good i.e. compliant with the WWW Consortium guidelines (& then we could put the following symbol on compliant pages if we wish):



I've also seen quite a lot on this forum about adhering to standards & bad coding etc. & members on here agreeing webdesigners should conform to the standards.

I thought that if you don't start your page with the correct opening 'xhtml guff' (sorry, can't remember technical term!) then it will not adhere to the WWW Consortium standards?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #9  
Old Mar 1st, 2007, 23:28
Most Reputable Member
Join Date: May 2006
Location: North West, UK
Age: 22
Posts: 1,173
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

But you have started with the correct doctype. That 'menu.html' is not a standalone page it is just a piece of html that is going to be inserted into a properly declared xhtml document. As long as your index.php has the correct doctype (and you have played by the rules) your page will still validate.

Pete.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #10  
Old Mar 2nd, 2007, 01:58
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

index.php should have all the XHTML declarations, an html, head and body tags, etc. Everything to make a site validate. menu.html will not have this because it's only part of the full document. It should still be valid XHTML, but it will not validate on its own. Only index.php should validate. Does that answer your question? Your question is a little hazy.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #11  
Old Mar 2nd, 2007, 01:58
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

Exactly ... it's the same as having

Code: Select all
<html>
    <head>
        <title>page</title>
    </head>
    <body>
        <p>Welcome to our site</p>
<h1>Navigation</h1>
<ul>
    <li>Home</li>
    <li>Contact</li>
</ul>
        <p>Copyright &copy; 2007</p>
    </body>
</html>
That's a XHTML/HTML page ... the only thing you've done differently is remove what's common to all pages (and that's what's in red) and import it when you need it.

The page is still index.php.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #12  
Old Mar 5th, 2007, 11:30
Junior Member
Join Date: May 2006
Location: UK
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

Sorry my question is a little hazy.

When I did my xhtml course our tutor said we had to put something like this at the top of the page to get W3C validation:

<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE html PUBLIC "-//W3C//xhtml1/DTD XHTML 1.0 Transitional//EN"
"http://WWW.W3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">


What you're saying is that ALL of this can be replaced with just:

<html>

so that's why I was a little alarmed & wondered if the page would still W3C validate? If it does then I'm happy with that but wonder why our tutor made us put all that stuff at the top of every page if it isn't necessary? Any idea?

One final thing, because the pages have the .php extension I don't think I can look at the page in a browser on my PC. I have to upload it to my host to look at it? Is there any clever way of testing the page or is the only way to upload it to the host?

Hope I'm not being too much of a pain asking these questions, I just want to make sure I really understand what I'm doing before making these changes.

Thanks
Lynn
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #13  
Old Mar 5th, 2007, 12:00
Ryan Fait's Avatar
Elite Veteran
Join Date: May 2006
Location: Las Vegas
Posts: 3,787
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

NEVER use <?xml version.... > as the first line of your code. Use only the <!DOCTYPE>. The ?xml tag is not required, and more importantly, it will throw IE into quirks mode which will in all likelihood cause problems.

Karinne was just shortening the document structure in her example. You'll want to include the doctype in the page. Karinne and I understand HTML more than you do, so forgive us for using shorthand when describing things

The reason why .php pages aren't showing up on your own computer is because PHP isn't installed on it. Install PHP and the pages will show up as they should.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #14  
Old Mar 5th, 2007, 13:14
Junior Member
Join Date: May 2006
Location: UK
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

Do you have an example page that I can look at just to see what code you have at the top of it before the <html> ? Not sure what I should be using now.

Thanks
Lynn
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #15  
Old Mar 5th, 2007, 13:18
Elite Veteran
Join Date: Jan 2007
Location: You know where
Age: 31
Posts: 4,617
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

Just the doctype - Recommended DTDs to use in your Web document.

See the template? ... just don't put the <?xml version="1.0" encoding="utf-8"?> line

HTML: Select all
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
 "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" lang="en-CA" xml:lang="EN-CA">

<head>
    <title>Some title</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    
</head>

<body>

</body>
</html>

Last edited by karinne; Mar 5th, 2007 at 13:20.
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #16  
Old Mar 8th, 2007, 21:54
Junior Member
Join Date: May 2006
Location: UK
Posts: 38
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

Hi

Just wanted to say a big thanks!!! I have changed all my pages on my website & I'm really pleased with the results!

L
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #17  
Old Jun 28th, 2007, 16:57
Reputable Member
Join Date: Mar 2006
Location: UK
Posts: 101
Thanks: 0
Thanked 0 Times in 0 Posts
Re: How to put your menu/static info. on every page

Quote:
Originally Posted by Weird1993 View Post
Or you could just use a template if you for some reason can't or don't want to use PHP.
Too right I don't want to use PHP! Can anyone tell me how to do this with a template in straightforward HTML?
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
  #18  
Old Jun 29th, 2007, 01:59
Elite Veteran