SUBSCRIBE VIA RSS


Subscribe to our feed

Symfony Experts

Symfony Experts
If you have an urgent question for a symfony-related issue, this is the place to ask.

Topics

TWITTER

Stack Overflow


The old fashioned way

RECENT TUNES

April 10, 2010 – 12:09pm Wordpress navigation, link to page or category

Here is a quick snippet of a non-elegant way to create a navigation for a wordpress template. This sample includes links to specific pages using get_permalink() and is_page(), along with get_category_link() and in_category(). Using these functions you can determine if each link should be in its active state or not.

$links = array(
  'Industry Studies' => array(get_permalink(12), is_page(12)),
  'Recipes' => array(get_category_link(3), ($categoryId ? 3 == $categoryId : in_category(3))),
  'Blog' => array(get_category_link(1), ($categoryId ? 1 == $categoryId : (in_category(1) && !is_page()))),
); 
 
$selected = false;
foreach ($links as $title => $link):
  $linkSelected = (!$selected && $link[1]) ? ($selected = true) : false;
  printf('<li><a href="%s" class="%s" title="%s">%s</a></li>', $link[0], ($linkSelected ? 'selected' : ''), $title, $title);
endforeach;
Posted in  Web Development   |     |  delicious  Digg

Post a Comment

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Click to hear an audio file of the anti-spam word