Forum Moderators: open

Message Too Old, No Replies

How do I use 'includes' for sitewide changes?

         

tigerflag

4:06 pm on Dec 4, 2006 (gmt 0)

10+ Year Member



I have an ecommerce site of 130+ pages and growing. It is written in standard XHTML with an external CSS stylesheet. I write with a text editor, not any page building software. I need an easier way to make sitewide changes to, say, the navigation panel or footer. Opening each and every page to cut, copy and paste is taking waaaaaaay too long.

I did a search here and found a mention of using something called "includes" to make separate files for these page sections. Then they can be edited once and will make the changes sitewide.

Does the use of includes affect accessibility for the blind?

Can anybody explain to a newbie how to do this? FWIW, the only languages I know are HTML/XHTML and a wee bit of CSS.

Thanks!

Quadrille

5:17 pm on Dec 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Exactly how to do it depends on your server and possibly your host. It may require changed filenames (eg file.shtml) - but that will be a one-off change.

The principle is dead simple:

You could have, for example, a links.html with all the link for your left margin; each page would just have 'include links.html' code in that spot.

So whenever you wanted to add a link, you'd revise the one file, upload it, and every page would change.

As all this happens at the server, the page itself would appear as if that code had been there all the time, so no implications either way for accessibility.

You'd need to edit each page once to insert the 'include' code, then it's a doddle.

I use them for dates, news, advertisements, links ....

monkeythumpa

6:13 pm on Dec 4, 2006 (gmt 0)

10+ Year Member



Is your server runing Windows, Linux, or both? There is different code for each but it is really easy to do.

rocknbil

8:24 pm on Dec 4, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I write with a text editor, not any page building software. I need an easier way to make sitewide changes to, say, the navigation panel or footer. Opening each and every page to cut, copy and paste is taking waaaaaaay too long.

Befoe considering includes, consider a robust page editor. I use Macromedia Homsite. If your "target text" is identical throughout, H.S. can rip through a thousand files on an extended search and replace in about 5 seconds. There are many robust text editors that can do this. The reason this is a good idea is so that your include files html doesn't require new URL's but there are workarounds to that too.

Does the use of includes affect accessibility for the blind?

No, it is (usually) a server-side technology that outputs plain test that would be identical to your static html.

Can anybody explain to a newbie how to do this?

As mentioned for windows servers it's different. For linux, verify that SSI's are turned on. The simple test below will tell you if it is enabled or not.

"Turned on" means you need your server to parse the documents and search for the SSI directive, indicated by the "include" line below. Normally a server parses documents only with an .shtml extension, but for SEO purposes you may want your server configured to parse all HTML for SSI includes. This is so your URL's don't change. Contact your ISP on how to set this up.

Le's consider the usual condition, you have a file named test.shtml:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Include test</title>
</head>
<body>
<h1>Server Side Includes</h1>
<!--#include file="test.txt" -->
</body>
</html>

then in test.txt:

<p>Hello world, this is my first include file.</p>

Throw these on your server in a test directory and see if it works.

Two important considerations:
1. The spaces before the closing --> are important.
2. If you store your included file in a DIFFERENT directory than the .shtml, use the virtual directive:

<!--#include virtual="/web/includes/test.txt" -->

If you get "An error occurred while processing this directive" it means that SSI is indeed operational but that you have an error or typo in your .shtml, and usually simply means the server can't find the file from the instructions in your directive.

That's really all there is to it.

Candid India

11:10 am on Dec 5, 2006 (gmt 0)



i completely agree that it all depends on your server and on your host.
According to host and server only it can be used

Quadrille

1:02 pm on Dec 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Find and replace is certainly a possible alternative - but it does mean FTPing every page, while SSI involves just one file.

Using templates, SSI and css is much more elegant and much less work than editing individual pages, once a site reaches a certain size.

Marcia

1:18 pm on Dec 5, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



My take is that PHP includes are the way to go. Then, in case other PHP functionality is used on the site at some later date, it'll all play nicely together. Use a file handler in .htaccess so that file extensions don't have to be changed.

For example, if PHP includes are used for global navigation (works the same way as SSI, BTW), changing just the one text file implements the change across the entire site, on whichever page the include is used, without having to upload anything new.

tigerflag

5:12 pm on Dec 5, 2006 (gmt 0)

10+ Year Member



Thanks everybody for your help. I would have answered sooner but never got any email notifications of replies.

My host uses a Linux server. He tells me that SSI is available for .shtml files. I use Linux, too, not windows. My text editor is Kwrite.

I did what rockinbil suggested. Made a directory called "includes", copied and pasted both files and put them in it. Uploaded and went online. All I got was permissions error messages. So I fiddled with permissions, making them the same as for Awstats, which I can access. No joy.

I like the idea of making changes via includes rather than from a batch change in a text editor. Seems a little safer and there's less uploading, too. But if I'm forced to use an editor, is there an easy one you can recommend that works in Linux? (I'm dumb when it comes to learning how to use applications.)

Any ideas what I should try next?

Siri Amrit

stever

11:54 am on Dec 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



If you have Linux, then one of the easiest ways is to write your includes as php.

The filenames need to end in php (unless you want to go around rewriting them which is probably not the stage to get into that kind of thing).

A php include looks (can look, there are other options) like this:

<?php
{
require_once("pathtomy/file.php");
}
?>

and what goes in the include file is exactly what would be in the html in the original page and nothing more.

Common uses for include files are navigation (easy sitewide changes), headerimage (seasonal changes, for example), footer (copyright changes - I've given up arguing the point about the year!), quicknav (boost to certain pages).

Added: here's a quick way to see if you can work with it >>

Save a current page as the same name but with a php ending. Add in the following code somewhere:
<?php
{
require_once("test.php");
}
?>

Now open a text editor and write the following in a blank file:

<p>Hello world</p>

and save the file as test.php in the same directory as the original file.

Upload both files to your server and see if you can see "Hello world" on your php page.

Quadrille

12:04 pm on Dec 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to be clear, the 'include' is NOT a complete html page; just the stuff code you need.

(no doctype, header or body tags)

tigerflag

5:23 pm on Dec 6, 2006 (gmt 0)

10+ Year Member



Well the .php test worked like a charm. Now my only concern is this:

How will changing all my pages from www.widgetstore.com/widget.html to www.widgetstore.com/widget.php affect my search engine rankings? Will I have to start out all over again at the bottom? What about all the people who have bookmarked my pages, if I go and change them from .html to .php? Will they get "Page not found" errors? I also have listings in directories all over the internet pointing to pages ending in .html. Can't possibly go back and change all those...

Quadrille

6:37 pm on Dec 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yes and no.

Each page will be treated as a new page; but your site will assimilate them quickly, like any other new page.

You might consider uploading the new stuff in sections, however, rather than the whole lot in one go, to avoid any risk of 'new site' issues.

While you won't see page rank for three months or so, that doesn't mean there isn't one!

There are server tricks to workaround; but for me, updating in sections has always worked (just watch the navigation! - xenu is your friend).

tedster

9:05 pm on Dec 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



This may be of use:

Parsing HTML as PHP [webmasterworld.com]

stever

9:32 pm on Dec 6, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You can 301 redirect your html pages using mod_rewrite in a .htaccess file. You can find details of how to do that over in the Apache Forum library [webmasterworld.com].