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 by in  Web Development   |  

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>