[thelist] PHP - good ways to indicate current page in navigation?

Christian Heilmann codepo8 at gmail.com
Sat Jul 22 15:58:43 CDT 2006


On 7/22/06, Jono <jono at charlestonwebsolutions.com> wrote:
> > I'd like to indicate what section the user is in by writing out a class on a
> >LI item dynamically server side.
>
> Tom,
>
> Take a look at these articles:
> [ 1 ] is from ALA's site, and is similar to what you mentioned in your
> original post.  [ 2a, 2b ] are also similar, but more dynamic, and more
> efficient, and a bit more difficult to set up - but worth the extra time and
> effort.  [ 2a, 2b ] cover far more than just keeping your navigation
> current, and are a small part of an excellent Usability and Branding
> Website;)
>
> [ 1 ] Keeping Navigation Current with PHP:
> http://alistapart.com/articles/keepingcurrent/

This example is horrible as it is not at all scaleable and just
plainly bad PHP - as was mentioned many times in the comments. With
ALA articles that are very technical ALWAYS read the comments (this
includes mine) as a lot of fixes and bugs are mentioned there.

All of the above solutions seem to use CSS as the indicator what the
current page is, and this is - plainly said - inaccessible and shows
that the author hasn't grasped the idea of semantic markup.

The current page should simply NOT link to itself, as a link to the
same page - unless it is a refresh link - is redundant and confusing.

The trick I used on many projects with PHP and highlighting the
current page is to do the following:

1) Keep all the navigation in one HTML include that is a nested list
2) Include this list in each document and compare the current location
(PHP_SELF) with the links in the include.
3) When there is a match, replace the link with a STRONG element and
add a "parent" CSS class to each LI above the one that has a replaced
link

All wrapped up: http://www.onlinetools.org/tools/easynav/

That way you have a navigation that is highlighted, you don't need to
add IDs to each navigation element (which reduces scalability
immensely) and maintaining the navigation is a piece of cake. Even
styling it is easy as you can style li strong{} as the current
element.

CSS is there to host the look and feel, don't use it to take over the
job of HTML or JavaScript, it is just not reliable. And PHP is there
to take over jobs that are not possible in HTML - like loops or
conditional output and not to provide fodder for CSS solutions that
can be easily done in PHP.


-- 
Chris Heilmann
Book: http://www.beginningjavascript.com
Blog: http://www.wait-till-i.com
Writing: http://icant.co.uk/



More information about the thelist mailing list