[thelist] PHP question (related to WordPress too)

Tom Dell'Aringa pixelmech at yahoo.com
Mon Jun 27 14:57:53 CDT 2005

Hi everyone,

I'm trying to get some dynamic highlighting working on my WordPress menus. Each nav item is
actually a category in wordpress at www.crossandthrone.com. The nav is dynamically built using a
function. I have a function available to me called 'is_category()' where I can tell what category
page I am on. Based on this, I want to add an ID to the LI item and the A tag.

The pertinent part of the code is as follows:

// figure out what category we are viewing - I added the next 3 lines
$current = "none";
if ( is_category('bible-study') ) { $current = 'bible'; }
elseif ( is_category('news') ) { $current = 'news'; }

// This is the part of the original function that writes out the LI items.
if ($list) {
  $thelist .= "\t<li id=\"$current\">$link\n";

So, right now if I click on 'news' then every LI ID will have 'news' as it's value - but that
isn't what I want. What I actually want to do is check and see if the category the user is on
(stored in the variable $current) is equal to the category being written out. If it is, then I
want to write out that ID. There is a variable that I can work with that holds this category name
called $category->nicename.

So I need something like so:

$thelist .= "\t<li

  if ($current == $category->nicename) { id=\"current\"; }


I can't seem to quite figure out how to do this. I'm guessing that 1) my equality check is not
right and 2) I'm not sure how to split up the code to get the IF statement in the middle of the LI
writing out.

Any help is appreciated.




Melissa: Ace, Where are you?
Ace Ventura: I'm in Psychoville and Finkle's the Mayor.

More information about the thelist mailing list