PDA

View Full Version : Amazon.com Style Folder Tabs


jimbo
12-11-2000, 08:15 PM
I'm working on a new site, and I am finally breaking down and using the "folder tab" style of menu. I want to include this menu using include(), but as it sits it only displays the original menu. Is there any way that PHP can determine what the current URL is, thus changing the color of the appropriate tab to "active", as well as the table underneath?

The page I'm working on right now is located at:

http://www.advancedhorizons.com/Spectraserv/index.php - right now the menu is static, but you will be able to see what I want to do.

Is this possible with PHP?

-jim

dank
12-11-2000, 09:00 PM
The following tutorial has some tips that you might find helpful:

http://hotwired.lycos.com/webmonkey/99/25/index2a.html?tw=programming

But, I found things much more to my satisfaction by running some regular expressions through $REQUEST_URI

Dan

jimbo
12-12-2000, 05:04 PM
Dan, are you trying to confuse me? ;)[nbsp][nbsp][nbsp][nbsp]I didn't realize that was you until I looked at your profile and saw your site :).

Anyway, I looked at that tutorial yesterday, and it didn't really tell me anything I didn't already know.

I, too, tried to do some stuff with $REQUEST_URI and all sorts of other environmental variables, but it didn't work.[nbsp][nbsp]Finally, on another forum I frequent where I asked the same question, somebody gave me a suggestion to use variables - I worked with it and liked it a lot, and it works (that's the most important thing :)).

I know you're sitting there reading this and thinking "I wonder what code he used to do this?" - well you're in luck:

I created a file called header.php, and put this code at the top for every tab (This is just the "Home" tab):


// BUTTON BACKGROUNDS
if (empty($bg_home)) {$bg_home = "#031883";}

// BUTTON FONT COLOR
if (empty($font_home)) {$font_home = "#ffffff";}

// BUTTON TEXT
if (empty($text_home)) {$text_home = "Home";}

// BUTTON CURVES
if (empty($left_home)) {$left_home = "$site/img/leftcurve.gif";}
if (empty($right_home)) {$right_home = "$site/img/rightcurve.gif";}


The HTML for the "Home" tab looks similar to this (I removed the escape characters for readability):


[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]<td bgcolor=&quot;$bg_home&quot; width=&quot;15&quot; align=&quot;left&quot; valign=&quot;top&quot; height=&quot;15&quot;><img src=&quot;$left_home&quot; width=\&quot;15\&quot; height=&quot;15&quot;></td>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]<td bgcolor=&quot;$bg_home&quot; align=&quot;center&quot; height=&quot;15&quot;><a href=&quot;$site/index.php&quot;><font face=\&quot;Verdana, Arial, Helvetica, sans-serif&quot; size=&quot;1&quot; color=&quot;$font_home&quot;>$text_home</font></td>
[nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp][nbsp]<td bgcolor=&quot;$bg_home&quot; width=&quot;15&quot; align=&quot;right&quot; valign=&quot;top&quot; height=&quot;15&quot;><img src=&quot;$right_home&quot; width=&quot;15&quot; height=&quot;15&quot;></td>


And then in my index.php file, I call the header like this:


$bg_home = &quot;#E0DBA6&quot;;
$font_home = &quot;#000066&quot;;
$text_home = &quot;Home&quot;;
$left_home = &quot;../img/leftcurve_on.gif&quot;;
$right_home = &quot;../img/rightcurve_on.gif&quot;;
include(&quot;header.php&quot;);


It's a little more work than I had wanted to do with it, but it is a lot LESS work than changing EVERY file every time I change the menu.

-jim

<edit to eliminate frivalous code>


[This message has been edited by jimbo (edited 12-12-00@4:11 pm)]

dank
12-12-2000, 08:13 PM
Dan, are you trying to confuse me? I didn't realize that was you until I looked at your profile and saw your site. Maybe my sig file will help?[nbsp][nbsp];)[nbsp][nbsp]

My eyes might be a bit too blurry right now, but it appears to me you are passing variables to the pages each time you want to load the appropriate tabs, correct?[nbsp][nbsp]Wouldn't you have to assign each page within the site to a set of variables?[nbsp][nbsp]It seems I'm missing something...

Here's an example of what I was talking about.[nbsp][nbsp]On the following page, I wanted everything in that directory and below it to have a secondary navigation system, but I didn't want to add anything other than the site-wide header and footer file.

http://www.activesalem.com/gfr/

The column on the right is triggered for anything in the &quot;gfr&quot; directory as follows in the footer file:

<?php $dircheck = eregi_replace(&quot;^\/([^\/]*)(\/)(.)*$&quot;, &quot;\\1&quot;, $REQUEST_URI); ?>
<?php if ( ($dircheck == &quot;gfr&quot;) &amp;&amp; !($print == &quot;yes&quot;) ): ?>
[nbsp][nbsp]html goes here...
<?php endif; ?>

I believe you could do the same thing by either placing the pages corresponding to specific tabs in their own directories (anything not in a specified directory gets the default tab) or checking for a consistently named file pattern.

Dtect
[nbsp]- trade secret, what's that?

edit:[nbsp][nbsp]In the code above, $print corresponds to an internal variable for flagging printable pages, which drop most navigation and formatting, i.e. http://www.activesalem.com/events/frolic/frolic_00_entry.php

------------------
The artist formerly known as Dluded
[This message has been edited by dank (edited 12-12-00@7:15 pm)]

jimbo
12-12-2000, 11:04 PM
I only knew you as &quot;Dan Kaplan&quot; - I just thought this &quot;dank&quot; character was stealing your thunder...[nbsp][nbsp];)[nbsp][nbsp]

it appears to me you are passing variables to the pages each time you want to load the appropriate tabs, correct?[nbsp][nbsp]Wouldn't you have to assign each page within the site to a set of variables?[nbsp][nbsp]It seems I'm missing something...
The way it works, is each tab is set to a default value, unless it is specified as something different.[nbsp][nbsp]On the pages I'm inserting the header onto I specify the &quot;Active&quot; variables, so to speak.

Say I'm doing the News page - I would call the header like this:


$bg_news = &quot;#E0DBA6&quot;;
$font_news = &quot;#000066&quot;;
$text_news = &quot;Home&quot;;
$left_news = &quot;../img/leftcurve_on.gif&quot;;
$right_news = &quot;../img/rightcurve_on.gif&quot;;
include(&quot;header.php&quot;);


Calling the header this way replaces the default variables specified in the header.php file with the &quot;Active&quot; variables for the appropriate page.

Everything I tried was 10x more difficult and involved than this way.[nbsp][nbsp]It almost seems too basic :).

-jim


[This message has been edited by jimbo (edited 12-12-00@10:05 pm)]

dank
12-12-2000, 11:18 PM
Say I'm doing the News page - I would call the header like this: I follow that much, but doesn't that mean every page with non-default tabs needs to have the header called with the appropriate values?[nbsp][nbsp]The way I understand what you are saying, it seems that somewhat defeats the purpose of include files -- ability to make mass site-wide changes on the fly (I'm most proud of having switched an entire site from non-frames to frames in about 5 seconds through include files while maintaining the design).

Dlight(ning)

jimbo
12-12-2000, 11:24 PM
ability to make mass site-wide changes on the fly
The way I'm doing this, I'm assuming the fact that I will be keeping this menu system.[nbsp][nbsp]I am doing this mainly because I plan on adding items to the current tab system.[nbsp][nbsp]Since this particular site is still in development, as well as all &quot;in development&quot; sites, included menus are a great thing to have, expecially since I'm constantly adding or changing sections.[nbsp][nbsp]This way, as long as I keep the same design, I can do this at will.

For example, tomorrow I could add a &quot;Contact Us&quot; tab - and it would show up on all the other pages as well.[nbsp][nbsp]The only drawback being that I have to add those 5 variables above the include statement.[nbsp][nbsp]But that is a small price to pay versus dozens of static page modifications.

-jim

SneakyDave
12-15-2000, 02:52 PM
I'm working on a new site, and I am finally breaking down and using the &quot;folder tab&quot; style of menu. I want to include this menu using include(), but as it sits it only displays the original menu. Is there any way that PHP can determine what the current URL is, thus changing the color of the appropriate tab to &quot;active&quot;, as well as the table underneath?

At www.baypal.com/tools (http://www.baypal.com/tools), I use the strstr() function to determine which &quot;tool&quot; the page is on with the $self variable.

Each tool is in its own directory. If the particular tool &quot;name&quot; is in the $self variable (by using the strstr() function), I make the background for the tab colored (the tool is &quot;selected&quot;), if not, the background is white (not selected).

Let me know if you need more information.
[This message has been edited by SneakyDave (edited 12-15-00@1:53 pm)]