
|
View Full Version : Update Navigation all at once.
Sneath Design 12-20-2005, 11:06 AM First off, sorry for the crappy title, I couldn't think of anything suitible.
Anyway I am creating a website that has navigation across the top and down the side of every page, now should I need to change a link I don't want to go throughout the entire website chaging the same link on every page. I would like to just update perhaps one file or something and that would change them all.
I dont want to use iframes becuase they suck, so any other suggestions are welcome.
Thanks. :ukflag:
the_pm 12-20-2005, 11:13 AM Includes are the way to go. The three most common methods are PHP, ASP and SSI (though SSI is rapidly losing popularity, in my observation).
The whole idea of an include is easy. You put a single line of code into every page, like this:
<?php include "path/include_file.inc";?>
And then you create an entirely separate document with the information you want to insert, in your case, navigation. Now, when you want to make a site-wide change, you change that one file, and the whole site updates.
You can take this a step farther by putting includes inside included files. I'll personally create subsection navigation for a site, put each subsection in its own include file, and call it into a page for displayed navigation, DHTML menus, the domain's site map, etc., all controlled from a single source. It saves a TON of time, and you can put together a really slick system!
Sneath Design 12-20-2005, 11:18 AM Thanks for the quick answer pm, I'll look into includes :)
Junkie 12-21-2005, 07:53 PM Includes are the way to go. The three most common methods are PHP, ASP and SSI (though SSI is rapidly losing popularity, in my observation).
The whole idea of an include is easy. You put a single line of code into every page, like this:
<?php include "path/include_file.inc";?>
And then you create an entirely separate document with the information you want to insert, in your case, navigation. Now, when you want to make a site-wide change, you change that one file, and the whole site updates.
You can take this a step farther by putting includes inside included files. I'll personally create subsection navigation for a site, put each subsection in its own include file, and call it into a page for displayed navigation, DHTML menus, the domain's site map, etc., all controlled from a single source. It saves a TON of time, and you can put together a really slick system!
Hey, pretty neat. Man, I'm so behind the times. I hadn't actually heard of includes until now. So, can includes be placed in an HTML page or does it have to be a PHP/ASP type page? I'd really like to start using includes, but I don't know either PHP or ASP. :bawling:
Website Rob 12-21-2005, 07:57 PM Not sure why anyone would think SSI is losing popularity? As long as people use 'html' for their pages there will be a need for SSI. Now, if one is coding in PHP then yes, using a PHP include is the way to go -- you cannot use PHP includes in a file that ends in '.html' for example.
For HTML pages requiring SSI, I find it's best to put all SSI files in one dir., preferably a top level one.
for example: public_html/includes/
Then name each file accordingly: s_top-nav.txt or s_left-nav.txt, and using 'txt' files or 'html' files for SSI makes no difference. Even if HTML code is used in a file that end with 'txt', it will parsed as HTML code. I put an 's_' in front so I know it's an SSI file and prefer 'txt' format because nobody can do anything nasty with a text file. ;)
<!--#include virtual="/includes/s_top-nav.txt" -->
That is the code one would use for where they want to put their Top Navigation -- presumable links and related coding.
Almost forgot, another popular include type is JavaScript.
<script type="text/javascript" src="/includes/buttonrollover.js"></script>
That code is typically used in the HEADER as it pulls JS code that needs to be pre-loaded. And when coding in XHTML, using JS includes insteading of inserting the code directly into the HTML page, is the only way to go. :D
Corey Bryant 12-21-2005, 08:02 PM For some more information on Server side includes (http://www.bignosebird.com/ssi.shtml). And using ASP includes (http://www.w3schools.com/asp/asp_incfiles.asp). You can tell a *NIX server to parse all HTML as SHTML but that could cause your server to slow down some.
And Junkie, you could still write HTML - save it as an ASP / PHP extension to use those includes. All you are basically doing is telling the server to parse the file before displaying it in the browser.
Using JavaScript - you might run the risk of some search engines not being able to read it correctly and your site might not be spidered, however it is still popular with some.
XMG-Eric 12-21-2005, 08:35 PM A quick solution would be using Find & Replace in Dreamweaver to replace a selected amount of code in an entire folder.
So for instance....you would copy the unedited navigation code...paste it in the find box...edit the links code paste it in the replace box and select the folder with the website...It would simply find and replace that code for all pages.
Thats a really cheap way, but works if you need a fast solution.
I'm totaly behind SSI, they are the best way to help make your content dynamic and easy to chage site-wide.
Theres a little hack you could use to parse PHP files under the .html extension if you dont want to go changing all your page extensions to .php.
Put this in your htaccess:
AddType application/x-httpd-php .php .html .htm
AddHandler application/x-httpd-php .php .html .htm
Then you can go really crazy and use that find and replace method above, by selecting your navigation code in 1 file and replacing it with a PHP Include in the site folder.
Good luck!
Junkie 12-21-2005, 08:42 PM And Junkie, you could still write HTML - save it as an ASP / PHP extension to use those includes. All you are basically doing is telling the server to parse the file before displaying it in the browser.
Sorry, but what do you mean that I can write an HTML page and save it as an ASP/PHP? Really?! I have no idea at all what I am doing in ASP or PHP. Anyway, I have a new website I'm designing right now in HTML for a client. You think I should go for it and save the stuff as ASP or PHP? Any risks that I might F something up?
WebDesignGold 12-21-2005, 10:27 PM I use includes myself. It's probably the most used method since ssi I think. Very helpful.
Actually, you don't need to know PHP more then saving your HTML files with ".php" instead of ".html" and adding the include line where you want it to be.
Here's an example document:
You have a site with horizontal navigation in the header that's the same for all your pages. Main content varies from page to page. Footer (with copyright notice for instance) is the same for all pages.
Create a text file and call it "header.inc". Put all code and content that's the same for all pages:
<!doctype html public "-//W3C//DTD HTML 4.0 Transitional//EN">
<html>
<head>
<title> Your Site Title </title>
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<link rel="stylesheet" type="text/css" href="style.css">
<script type="text/JavaScript" src="your_javascript_file.js"></script>
</head>
<body>
<div id="menu"><ul><li>link</li><li>link</li><li>link</li><li>link</li><li>link</li></ul></div>
Create your "index.html" and all the other files you'll need like this:
Put this line first:
<?php include("header.inc"); ?>
then main content goes here using HTML coding..
Last, put a similar php-code as above to include the footer:
<?php include("footer.inc"); ?>
You'll create your footer-file just like you did with the header.
A text file, call it "footer.inc". Put your footer info in there.
For example:
<div id="footer">Copyright © 2005 Yoursite.com</div>
</body>
</html>
Then, when you need to change something in the header or footer, just edit the respective inc-file.
That was the easiest and simplest way.. there are more sofisticated ways out there. Just do a search.
You could, for example, make the title as a variable in the inc-file in order for your pages to have different titles.
chuck232 12-21-2005, 10:32 PM I did as the_pm showed here (and did a bit of reading online) and I changed my test index.html to index.php with no problems at all. I've got the include function working now. I'm so glad I won't have to recode every single page the next time I want to update the menu! :D
innovation 12-21-2005, 11:56 PM Which is why PHP is for. You use one page for every page, except that the content changes.
<? if ($id=="") { include("news/news.php"); } else { include("$id"); } ?>
the news/news.php is the content displayed whenever the person visits your index.php. Then, the rest of the code makes sure that you can create TXT file content and just link to it like this: index.php?id=content.txt.
Junkie 12-22-2005, 12:23 AM Which is why PHP is for. You use one page for every page, except that the content changes.
<? if ($id=="") { include("news/news.php"); } else { include("$id"); } ?>
the news/news.php is the content displayed whenever the person visits your index.php. Then, the rest of the code makes sure that you can create TXT file content and just link to it like this: index.php?id=content.txt.
Great tips in this thread. So, any advantages/disadvantages to saving your page as a PHP instead of ASP? I thought ASP was more common. After all, it is Microsoft supported and all. Which one should I use, PHP or ASP?
the_pm 12-22-2005, 10:45 AM Great tips in this thread. So, any advantages/disadvantages to saving your page as a PHP instead of ASP? I thought ASP was more common. After all, it is Microsoft supported and all. Which one should I use, PHP or ASP?I don't think it matters all that much. Windows servers can support PHP just fine, and *nix servers can support ASP...mostly just fine. It's a matter of whether you choose a provider who will support whichever technology you choose to use.
At this point though, I'd say base your decision on which one you are more likely to use when it comes to writing/installing other Web applications, and just make sure your host supports your choice.
A quick solution would be using Find & Replace in Dreamweaver to replace a selected amount of code in an entire folder.Beware! One little slip of the finger, and you've rewritten a whole Web site with borked code which cannot be undone!
Not sure why anyone would think SSI is losing popularity?My understanding is that SSI is the most server-intensive of the include options, and that ASP/PHP were taking over as the more prevelent choices. I could very well be wrong :)
NorthWest 12-22-2005, 11:14 AM Not to cause anymore confusion, but there is also;
<cfoutput>
<cfinclude template="includefile.cfm">
</cfoutput>
I know that some people may look down upon Coldfusion, but it still holds a little place in the market and it has its strengths. Yes, you might have to pay more for the hosting and that might be a drawback for the developer, but the language still has a lot of capabilities.
you cannot use PHP includes in a file that ends in '.html' for example.
Not natively, but you can tell the server to parse html files for PHP. There's a slight performance hit for pages that have no includes, but if you'd made the whole site as PHP, it would still be parsing them all anyway...
In your .htaccess file for this site, add this on it's own line:
AddType application/x-httpd-php .html
Create a text file and call it "header.inc".
Bear in mind that more often than not, a file named ".inc" will happily display the raw code when called via browser. To protect potentially sensitive code, it's better to name them all ".php", or even ".inc.php"
Corey Bryant 12-22-2005, 12:02 PM Sorry, but what do you mean that I can write an HTML page and save it as an ASP/PHP? Really?! I have no idea at all what I am doing in ASP or PHP. Anyway, I have a new website I'm designing right now in HTML for a client. You think I should go for it and save the stuff as ASP or PHP? Any risks that I might F something up?
Yes - afterall, that is what I did and how I started using ASP includes. For example
<table style="width: 100%; border-collapse: collapse">
<tr>
<td style="width: 25%;">nav</td>
<td style="width: 75%;">content</td>
</tr>
</table> can be all the <body> code you need and save it as ASP. it will come up the same just as HTML on a Windows server. Now by using <table style="width: 100%; border-collapse: collapse">
<tr>
<td style="width: 25%;"><!--#INCLUDE FILE="includes/nav.asp" --></td>
<td style="width: 75%;">content</td>
</tr>
</table>, you can pull the nav.asp page from another file.
If you do use include with folders, etc you might consider using virtual hyperlinks to reference your paths on your site.
sabian1982 12-22-2005, 07:18 PM when im using includes (using php) i dont use .inc but always .php is this incorrect or doesnt it matter on the included file type??
It would only matter if the included document had sensitive info in it, such as db connection data, or something you wouldn't want users to get their hands on. PHP would show as a blank page when called directly, unless it had something in it to write to the page.
|