Forum Moderators: phranque

Message Too Old, No Replies

Dynamic Site Layout

What method would you use?

         

CNibbana

12:12 am on Nov 22, 2003 (gmt 0)

10+ Year Member



My website is growing to such a large size that the thought of a future layout change or even a basic change to my navigation menu (which would currently require an html update across all pages) is scary.

Currently, the header and navigation menu elements of all my pages are static and only the changing content occurs within the center of the page. If I change any html in the header or menu I have to go back and change it on all pages. Quite a chore.

I know how I could call the header and menu with a Javascript function and create them as seperate .js files, but I'm thinking there has to be a better way.

Any suggestions?

Distel

12:51 am on Nov 22, 2003 (gmt 0)

10+ Year Member



I would go for server-side scripting, with PHP as my preferred choice. This is a technique I use a lot:

Step 1: generate an "array" file (i.e. a separate PHP file which contains an associative array with all your filenames). Like this:

<?php

$myarray = array(

"one" => array("pageone.php"),
"two" => array("pagetwo.php")

);

?>

Step 2: Create your index.php file, which contains all of your static elements (company logo, navigation menu, footer, ...). The part which should be dynamic can then be filled in using the array and using the URL of the requested page.

For example, in this case your navigation menu should contain links towards "one" and "two", using these URLs: "index.php?cont=one" and URLs: "index.php?cont=two" (note that you can replace this "cont" thing with a variable name of your choice). When the user clicks "one", the page "index.php?cont=one" will be loaded. So he will get your index page, containing all static info, but you can then have PHP replace all dynamic info by using the URL. The variable "cont" you see in the URL will automatically be available in PHP, so you can put the following code in your index page where the dynamic info should come:

<?php

if(isset($_GET["cont"]{
require("arrayfile.php");
include($myarray[$cont][0]);
}
else{
include("main.php");
}

?>

Here's what happens:

1. The user enters your site. the URL is simply index.php, so no $_GET["cont"] variable is set. The "main.php" page will therefore be inserted where you put the above code.

2. The user clicks on the "one" link, which loads "index.php?cont=1". In this case, $_GET["cont"] is set ($_GET variables are taken from the URL), so the file "arrayfile.php", containing $myarray will be loaded, making $myarray available for use. Then, the script looks includes the file that corresponds to this:

include($myarray[$cont][0]);

In this case, $cont is set to "one", so he will look for $myarray["one"][0]); In arrays, the first element is accessed with the number "0", so the first element of the "one" array is included, which is the pageone.php file.

If you're not familiar with PHP, this may look a bit complicated, but it really isn't.

You can also see now that you can dynamically insert any page item you want, based on the URL, including the page's title and meta tags.

Hope this helps. :)

Distel

12:53 am on Nov 22, 2003 (gmt 0)

10+ Year Member



I see I made a small mistake in the URL I used as an example above. I wrote this:

2. The user clicks on the "one" link, which loads "index.php?cont=1". In this case, $_GET["cont"] is set ($_GET variables are taken from the URL), so the file "arrayfile.php", containing $myarray will be loaded, making $myarray available for use. Then, the script looks includes the file that corresponds to this:

and it should be this:

2. The user clicks on the "one" link, which loads "index.php?cont=one". In this case, $_GET["cont"] is set ($_GET variables are taken from the URL), so the file "arrayfile.php", containing $myarray will be loaded, making $myarray available for use. Then, the script looks includes the file that corresponds to this:

;)

Shannon Moore

3:43 am on Nov 22, 2003 (gmt 0)

10+ Year Member



And I'm not as sleek a PHP geek as most, so I just use PHP include files for the static elements (header, navigation, footer, etc.) and individual PHP pages for each unique page. For example, in place of my navigation menu which appears on all pages of my site, I use:
<?php include ('http://mydomain.com/includes/global_nav.inc');?>

I used to have a static setup just as you describe, and initially converted to using includes by using SSI (Server Side Includes) and having my Apache server parse all htm documents as SSI (you could just as easily name the pages .shtm or .stm, instead.)

It was a relatively easy transition from there to doing PHP pages with PHP includes. I just use mod rewrite to rewrite requests for .htm or .html files to .php, *if* no .htm or .html file exists. (Saves me some broken links from related niche sites that are no longer updated, still linking to my now non-existant .htm/l files, but still serving up some visitors my way.)

Lots of ways to do it... You can even do it strictly in Dreamweaver using templates, though the projects I tried that on didn't convert me to it (others I worked with dug it, though.)

Distel

3:55 am on Nov 22, 2003 (gmt 0)

10+ Year Member



It's been quite a while since I used SSI, but I remember it being quite slow at times. I have no idea why, especially since they are server side includes, but Netscape 4.7 seemed to have a lot of trouble with SSI's which were placed several layers deep in nested tables. I remember timing it, and while my IE4 loaded the page in about 1 second, it took NS4.7 one minute and a half (!) for some reason. And that was on my local PC :-\

shasan

4:05 am on Nov 22, 2003 (gmt 0)

10+ Year Member



PHP includes all the way! :) I don't know WHAT I would do without them.

shasan

4:20 am on Nov 22, 2003 (gmt 0)

10+ Year Member




<?php include ('http://mydomain.com/includes/global_nav.inc');?>

Just wanted to point out that while Shannon's method will work famously, using the 'http' ends up throwing off web stats because it's your own domain sending an HTTP request for the include file. (server thinks it's an outside visitor, so you get a 'hit' for every time the include file is accessed).

Best way is to use a local path like so:

<?php include ('/home/www/yourdomain/includes/global_nav.inc');?> (or whatever the path to the file is)

Same deal if on windows, just replace *nix path with windows path to the file.

Just two cents :)

Shannon Moore

4:31 am on Nov 22, 2003 (gmt 0)

10+ Year Member



Thanks for pointing that out... I should have changed it, but my laziness got in the way there. Good catch.

Distel

4:33 am on Nov 22, 2003 (gmt 0)

10+ Year Member



That's actually two interesting cents there. I hadn't really thought about messing up visitor stats with absolute paths before.

RobinC

4:35 am on Nov 22, 2003 (gmt 0)

10+ Year Member



Personally I also like php includes, but I prefer to include a single common file, then have a do_header() function call at the top, and do_footer() call at the bottom - that way there's only one file to update, and you can pass variables to them (so you can ie. have the page title repeated in the header, before other header stuff)

Robin

ogletree

4:37 am on Nov 22, 2003 (gmt 0)

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



[webmasterworld.com...]

Did you read message 86

It looks like GG thinks dynamic sites are bad.

Shannon Moore

4:46 am on Nov 22, 2003 (gmt 0)

10+ Year Member



Let's not throw the baby out with the bathwater. Most spiders, including Google, have some trouble with (or don't index as deeply on) pages that have long querystrings,
eg: htt*://somedomain.com/page1.php?var1=1&var2=1&var3=1&var4=1

However, I've found Google does a reasonably good job with short query strings and then there's always mod rewrite (on Apache; I'm sure there's an IIS equivalent way to do it) to rewrite the URLs of truly hideous dynamic pages to make them more palatable... just look how successfully Amazon's own pages are indexed, among others. :)

Distel

4:47 am on Nov 22, 2003 (gmt 0)

10+ Year Member



AFAIK, dynamic sites are properly indexed by Google up to a certain point. I think it's a matter of limiting the variables in your URL and keeping them small. Other SE's may react differently to dynamic pages, though.

ogletree

4:51 am on Nov 22, 2003 (gmt 0)

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



Reguardless if some site has dynamic links and is doing fine there is a chance that it won't work. I have seen several examples where dynamic URL's was very much disliked by Google. If you have an old site with high pr maybe. I am in the middel of flattening all my sites and it has helped. Google used to like my pages but just quit updating and adding them one day. They updated and added a few here and there but all around it did not seem to like them. I switched to a flat site and Google was much happier. You can rewrite in IIS that is a good way to go. ISAPI rewrite is the name of a good program.

shasan

5:10 am on Nov 22, 2003 (gmt 0)

10+ Year Member



same here, it's not all that difficult to use rewrite (mod_rewrite in my case), so I figured what the hey, better safe than sorry.

lorax

4:05 pm on Nov 22, 2003 (gmt 0)

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



where dynamic URL's was very much disliked by Google. If you have an old site with high pr maybe. I am in the middel of flattening all my sites and it has helped.

There has been much discussion on this very subject here at WebmasterWorld. I have opted to go with dynamically driven website for a recent project. The entire site is based on a few template pages that are reconfigured to fit the content as needed. The site appears as if it were static and looks like it has hundreds of pages of content - when in fact it does not. The only includes I have are for the header and nav areas. The rest of the data lies within a MySQL database. Some of it lives in another website's database. And while I don't have stats on how well the spiders do or don't like it (it hasn't been published yet) I strongly suspect they won't even know the difference.

And if they don't like it for some reason directly related to the fact that it is a dynamic content engine then I believe they will sooner or later. The SEs will recognize this methododology of building and maintaining a website is quite viable and in fact becomes necessary to manage a website with many hundreds of pages of content.

IMHO unless you are abusing the technology in some fashion (or doing something else the SEs don't like), you're website will be found and indexed fine.

ogletree

4:11 pm on Nov 22, 2003 (gmt 0)

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



That is good and all. I am just saying that some people have had problems and that GG said to stay away from it. If you want to be safe have a site that has normal looking URL's. Dynamic content does not seem to be a big deal it is URL's that are the problem. With asp you can have a site that has one real page and the rest are that page with a?. Don't do that I did and have regreted it.

lorax

8:38 pm on Nov 22, 2003 (gmt 0)

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



>> If you want to be safe have a site that has normal looking URL's.

Correct - that is what I meant by URLs that look as if they were static. They look like they're .html files. Ah, the wonders of the Apache rewrite directive.

jamesa

3:54 am on Nov 23, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Just to clear up any confusion, this:

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

... and this:

http*://domain.com/script.php?name=value

...are two entirely different things (though often done together). The former appears static to Google, and you can even keep the .htm or .html extensions if you like (as has been mentioned). Only the latter looks dynamic to Google.

I'm 100% positive GG was referring to the latter scenario and not the former.