Hi! I'm Gordon Mackay, a web developer from the Highlands of Scotland. On this site you will find my photos, free CSS templates, free Adobe Fireworks graphics and some PHP code to use in your projects. Enjoy!
The product of today’s messing around with WordPress custom taxonomies in a bid to finish a client website - I needed to generate a navigation based on categories stored in a custom taxonomy.
Here’s the gist of it:
function displayTaxonomyNav($taxonomy, $baseURL)
{
$output = NULL;
$rangeNames = get_terms($taxonomy, 'orderby=id&hide_empty=0');
foreach($rangeNames as $range)
{
$output .= '<li><a href="' . $baseURL . $range->slug . '/">' . $range->name . '</a></li>'."\n";
}
return $output;
}
When you call the function in your template just change $taxonomy to the name of the custom taxonomy you registered, and the $baseURL to the base page to display the items within the categories:
<ul id="navigation-product-range">
<?php echo displayTaxonomyNav('product-range', '/products/range/'); ?>
</ul>
That’s all there is to it really.
Comment via Twitter
© All text and images copyright 2013 Gordon Mackay. All Rights Reserved.