Credit Cards - Hotels in Krakow - Loans - Credit Cards - The eBay Song

PDA

View Full Version : Sitewide sidebar in CSS/HTML


El Duderino
Nov 2nd 2007, 3:00 pm
I have a 30-page site set up on CSS and HTML. Every time I want to add or change a link on the sidebar, I need to make it 30 times. I know there is an easier way and keep seeing references to "includes". Can anyone give me some pointers on what I need to do?

frankcow
Nov 2nd 2007, 3:25 pm
You should use SSI, or PHP to create the include files.

tarponkeith
Nov 2nd 2007, 3:39 pm
FrankCow is right, use SSI...

This is a simple example, how I use SSI to help out... Almost everything is stored in external files, so it's easy to change the entire site...



<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>



<!--#include virtual="/static/files/inc_header.html" -->

<div id="main_body">
<h1>Welcome to ...</h1>
<!-- content here -->
</div>


<!--#include virtual="/static/files/inc_footer.html" -->

El Duderino
Nov 2nd 2007, 3:50 pm
Thanks guys. Looks like that will work. It looks like I have to re-create all .html files as .shtml. What do I need to do about all of my inbound links? Do I need to set up a whole bunch of 301 redirects or will browsers automatically pass traffic along to .shtml files?

jDare
Nov 2nd 2007, 4:33 pm
Ooo, I would not use redirects or change your page names if you care at all about SEO (Search Engine Optimization) or where you pages are in the search engines. I would strongly suggest PHP. You only need to learn like 5 lines of code in php and the rest you can do in HTML. Is your server running PHP?

El Duderino
Nov 2nd 2007, 8:54 pm
Yes, it does run PHP. I definitely don't want to take an SEO hit. What would I need to do to keep my current html files?

jDare
Nov 5th 2007, 8:04 am
This is a pretty simple way around it and without having to know much php.

Create a new file called header.php (or whatever you name it) and include the following:
<?
function printHeader()
{
?>

<!-- Normal HTML code goes here. -->

<?
}
?>

At the top of each html page that you want to include your header, before the <html> tag, put this:
<?php include('header.php');?>

header.php being the file with all the header code. If you put it in a folder then you will need to change the path to be folder/header.php and so forth.

Then, where ever you want the header to be located in each file, place this tag:
<?php printHeader(); ?>

You might have some issues if your .htaccess file is not set to read php code in an html file. If so, add the following code to your .htaccess file:
AddType application/x-httpd-php .htm .html .php

This way, you just need to change the one header.php file and all your other pages will be updated automatically. You can do this for a footer, sidebar, or whatever you want. The bots see your page exactly the same though. This will not hurt your pages SEO wise at all and you will not need to change the names of your files. Hope this helps!

tarponkeith
Nov 5th 2007, 8:19 am
You might have some issues if your .htaccess file is not set to read php code in an html file. If so, add the following code to your .htaccess file:
AddType application/x-httpd-php .htm .html .php

Changing .htm and .html files into .php files seems dangerous... I wonder if there's any side effects to that?

El Duderino
Nov 5th 2007, 7:59 pm
thanks a lot jDare. very helpful stuff.

twistedspikes
Nov 6th 2007, 10:16 am
Using a SSI would be your best bet. But it depends if your server supports any SS languages, which it probably will, but you never know.

Other than that there is always frames (which I won't recomend and hope for everyone that you don't use them).

ps JDare, you don't need half that stuff you said.

<?
function printHeader()
{
?>

<!-- Normal HTML code goes here. -->

<?
}
?>

only needs to be this:

<!-- Normal HTML code goes here. -->

and then place this wherever you want the header to go:

<?php include('header.php');?>

No need for the function. It's very unlikely that someone would put their header in twice, or a set of links in twice on one page, which is the only reason for using a function.

jDare
Nov 6th 2007, 1:31 pm
True, I only put in the function just in case you put other functions in the same file. You could put your header, sidebar, and footer all in one file if you really wanted by just creating different functions. But if you only want to do one thing, twistedspikes has a point.

longhornfreak
Nov 6th 2007, 8:23 pm
you could also use


<?
echo file_get_contents("sidebar.php");
?>

mrpeabody23
Nov 6th 2007, 9:25 pm
As an experiment try renaming one of your pages to PHP, try a 301 on another and .shtml on the last and see what the effect is. Are you making the same changes in each file, i.e. adsense change, link change etc? Perhaps a tool like grep could help.

Cheers

Dan Schulz
Nov 8th 2007, 2:36 am
How could you guys forget about the PHP and Server Side Includes thread I've linked to in my signature here already? ;) (By the way, that link goes to a thread here on the Digital Point Forums.)

http://forums.digitalpoint.com/showthread.php?p=2145250#post2145250