Forum Moderators: not2easy

Message Too Old, No Replies

Footer throughout site

         

terrybarnes

5:30 pm on Nov 30, 2008 (gmt 0)

10+ Year Member



I have a footer DIV on each page of my site but if I ever change the footer then I have to do so on each and every page. I'm sure there's a way but I don't know how to do it whereby that footer DIV calls in content from somewhere else?

lavazza

6:04 pm on Nov 30, 2008 (gmt 0)

10+ Year Member



You might want to read up on server side includes [google.com]

If you have php on your server (if you don't, I'd recommend finding a new host) then something like this ought to do the trick:

[pre] </head>
<body>
<?php include ("myIncludesDirectory/myHeaderFileName.php"); ?>
<!-- main contents here -->
<?php include ("myIncludesDirectory/myFooterFileName.php"); ?>
</body>
</html>[/pre]
where myHeaderFileName.php and myFooterFileName.php can be written in 'regular' HTML but saved with a .php extension

terrybarnes

6:09 pm on Nov 30, 2008 (gmt 0)

10+ Year Member



Fantastic - thanks for this - looks like I'll be doing a bit of reading for the next few days ;-)

Swanny007

6:15 pm on Nov 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



FYI, I've taken it a step further and use this format (look at the head section), it's useful for including the same CSS file and other information that is the same throughout the site:

<?php include('includes/doctype.php'); ?>
<html>
<head>
<?php include('includes/head.php'); ?>
</head>
<body>
<?php include('includes/header.php'); ?>
<!-- main contents here -->
<?php include('includes/footer.php'); ?>
</body>
</html>

doctype.php contains this:

<!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">

head.php contains this:

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<link rel="stylesheet" href="/includes/style.css" type="text/css" />

terrybarnes

7:18 pm on Nov 30, 2008 (gmt 0)

10+ Year Member



Thanks for this - very interesting stuff. Two questions:

Does it have any effect on SEO? I.e. will the item that's getting called in get recognised by google etc?

I presume I just add the relevant tag to where abouts i want it included in the html i.e.

<div id="footer">
<?php include('includes/footer.php'); ?>
</div>

lavazza

7:39 pm on Nov 30, 2008 (gmt 0)

10+ Year Member



Does it have any effect on SEO? I.e. will the item that's getting called in get recognised by google etc?
The Google-bots effectively read the page just the same way as a regular browser does...

If you go to a site that uses php includes and view the source code, you won't see (for example)

[pre]<div id="footer">
<?php include('includes/footer.php'); ?>
</div>
[/pre]

instead you'll see something like

[pre]<div id="footer">
<p>
this is my footer
</p>
<p>
Copyright &copy; 2006 ~ 2008
<a href="http://www.example.com/contact.html"
title="webmasters contact details">
Blue Widgets Inc</a>
~ All Rights Reserved
</p>
</div> [/pre]

So... no... it does not have any effect on SEO


I presume I just add the relevant tag to where abouts i want it included in the html i.e.

<div id="footer">
<?php include('includes/footer.php'); ?>
</div>

Yep

and you could incorporate the <div id="footer"> and </div> AND </body> and </html> into <?php include('includes/footer.php'); ?>... so then, you'd just write

<?php include('includes/footer.php'); ?>

and your page is finished

:)

[edited by: lavazza at 8:01 pm (utc) on Nov. 30, 2008]

buckworks

7:56 pm on Nov 30, 2008 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Google has no trouble recognizing content that is served by means of includes.

terrybarnes

8:01 pm on Nov 30, 2008 (gmt 0)

10+ Year Member



Thanks for everyone's help with this - it will certainly save me a lot of time only having to change one or two files rather than 20 or so pages!

lavazza

8:21 pm on Nov 30, 2008 (gmt 0)

10+ Year Member



Yep

And, when for example HTML-5 comes out...

Change doctype.php (and maybe head.php if you want/need to change the charset to, say, UTF-8) and hey presto, you're done! :)

terrybarnes

8:28 pm on Nov 30, 2008 (gmt 0)

10+ Year Member



I'm absolutely loving this - I wish I'd have learned this a few years ago! Oh well, better late than never I supppose ;-)

Swanny007

8:46 pm on Nov 30, 2008 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Technically I call doctype.php first.php but you can call it what you want. It's handy because it's easy to drop in any other code there like caching code, gzip code, etc.

Oh, and Terry, wait until you have 100+ pages, this will save you even more time ;-) I use that format on every site I build. And to think when I started I used Frontpage (it involved updating every page with the updated footer code). Ugh.