Forum Moderators: coopster

Message Too Old, No Replies

Help...Navigation System Challenge!

How should I code this navigation system

         

soundmachine

8:37 pm on Aug 14, 2003 (gmt 0)

10+ Year Member



I'm still a PHP newbie and I'm trying to figure this out! Here is my scenerio...

I have a website...with main categories...and sub categories...

I have already separated the site into one index.php page that includes my header and includes my footer...

I have main category buttons at the very top...and a place for TEXT HYPERLINKS on the LEFT.

Now when I click a category button at the top, I want it to load the subcategory links for that category on the left...For example...When I click the About button on the TOP...I want the follow text links to open up on the left..."DJs, Light Tech's, Job Opportunities, Company Info".

Here's the challenge, I have static header right now (the header contains the information for the top and the left side bar! I made it like that so that if I change anything on the header, it will be applied through the entire site. Not just one category (in which I'd have to go through all the categories that have customised subcategorical links and change all of them).

So I guess I need to make this header dynamic, but how? Or perhaps separate the left side navigation? I'd appreciate ANY help!

jatar_k

2:12 am on Aug 15, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



Welcome to WebmasterWorld soundmachine,

I would suggest making your left nav dynamic.

You could maybe set a variable for the section you are in.

$section = "dj";

then for each of those variable you do a little test in the nav

if ($section == "dj") {
// dj links here
}

and then have that for each section.

make sense?

waitman

3:55 am on Aug 15, 2003 (gmt 0)

10+ Year Member



I have done something similar to the following on at least 150 sites, works well and is easy to manage.

create a layout.html file

<html>
<head>
<title><!--Title--></title>
</head>

<body>
<table border="0" width="100%" cellspacing="1" cellpadding="1">
<tr valign="top">
<td width="150" height="350"><!--Navigation--></td>
<td height="350"><!--Content-></td>
</tr>
</table>
</body>
</html>

you should use comments, then you can manage the layout in something like dreamweaver. if you split up the layout into pieces ("header.php" "footer.php" etc etc ) then you end up with a real serious pain making changes.

my way also makes graphic designers like you a bunch.

then in index.php you read in the layout, inject the content and navigation, and anything else you want.

index.php:

<?php

$layout=@join('',@file('layout.html'));

$content = '<h3>this is the page</h3>

<p>Welcome to the page</p>
';

$title = 'fafafafoooolin';
$navigation = '
<div><a href="index.php?page=foo">foo</a></div>
<div><a href="index.php?page=boo">boo</a></div>
<div><a href="index.php?page=etc">etc</a></div>
';

$html = str_replace('<!--Content-->',$content,$layout);
$html = str_replace('<!--Navigation-->',$navigation,$html);
$html = str_replace('<!--Title-->',$title,$html);
echo $html;
?>

So if you use something like mod_rewrite, you build one index.php that is "the content engine", then your engine has intelligence to run php scripts that fill up $content, or you load in static html files into $content, and inject it into the template.

you can also get crafty and select alternate layouts for different content types, and adjust the content accordingly. one time, just for s&g, i had a site spitting out validated xhtml content to ie 6 browsers and validated html 4.0 content to all others. also, you can modify the content for wap, wml, etc.

so that's my suggestion ;-)

take care,

[edited by: waitman at 4:01 am (utc) on Aug. 15, 2003]

jamesa

3:56 am on Aug 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



What jatar_k said. There's no reason not to have PHP code in your header include.

jamesa

4:15 am on Aug 15, 2003 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Ha, looks like waitman and I were posting at about the same time... I like that approach, waitman. Thanks for that.

waitman

4:55 am on Aug 15, 2003 (gmt 0)

10+ Year Member



i have been using that strategy for years, and it has helped me whip out dynamic sites in a jiffy. i highly recommend it.

when i started building dynamic sites, i tried the head.php / foot.php, turned in to a nightmare when you had to make updates.

especially working with graphic design teams, and they want to try to update the look, etc of the site.

i have had good luck keeping content, code, and layout separate. content can go in a database or you can have flat html files (that do not contain any of the template ;-)

makes management a breeze.

take care,

soundmachine

4:08 pm on Aug 15, 2003 (gmt 0)

10+ Year Member



Hey guys, thank you both for your solutions...
I'll be trying both of them today to see which one fits my needs better. Jatar_k...a couple questions on your solution...

-So are you saying to make the left SEPARATE from the top (in two separate includes)? Or does it not matter?
-Where would I put these variables to show which categorical section I'm in?
-How would I call upon the variable? (uh...make the text hyperlink...index.php?section=dj ?)
This is the test I currently have...

<?php
if ($section == "about") {
echo ("<a href="about/dj.php">About</a>");
echo ("<a href="about/lt.php">Light Techs</a>");
echo ("<a href="about/jobs.php">Job Opps</a>");
echo ("<a href="about/compinfo.php">Company Info</a>")
}
if ($section == "portfolio") {
echo ("<a href="porfolio/venues.php">Venues</a>";
//next link and so on
}
?>

And so on and so forth through the sections I already have...is this right?

Sorry I'm a newbie, but I'm trying to learn! :) Thanks you guys for your tremendous response so quickly!

jatar_k

5:54 pm on Aug 16, 2003 (gmt 0)

WebmasterWorld Administrator 10+ Year Member



So are you saying to make the left SEPARATE from the top

it doesn't matter but I would put them in the same file.

Where would I put these variables to show which categorical section I'm in?

well in the top of each file you could have a $section = "sectionname"; before you include the menu. If you have the site seperated logically so each section is in its own directory you could have the menu itself figure out the directory it is in and serve up the appropriate menu.

is this right?

looks good to me