NOTE: Bad error fixed.
Current item used to be defined as tax_item_#current_item instead of tax_item_# current_item.
Bad CSS error; also modified the output from tax_item_# to display current taxonomy name, as well as added a new class with (taxonomy name)_item. Should make it easier to theme.
WordPress is very, very powerful, but there are a few things its lacking. Namely, listing the items of things other than pages & categories in nice little lists.
Now, I could wait until the guys at WordPress came and made a function, or I could program one myself… Which one do you think I did?
BSFunctions 1.1
This may or may not be the beginning of the BS WordPress collection, so download it and see!
To call this function, just type in <?php bs_list_taxonomies(‘taxonomy_name_here’,'extra_args_here’) ?>
Please use this wherever, I want to see my work out!
Modify, modify, modify as well but PLEASE leave the author statement intact, add yourself as a second author if you want.
/**
* @author Ben Stolovitz <ben@stolovitz.com>
*
* @uses wp_parse_args
* @uses get_terms
* @uses get_bloginfo
*
* @param string $taxonomy Required. The taxonomy you want to list.
* @param array $args Optional. Override default arguments.
* @return string Returns an HTML list of items in a taxonomy.
*/
function bs_list_taxonomies($taxonomy, $args=”) {
$defaults = array(
‘title_li’ => ucfirst($taxonomy),
‘echo’ => 1,
‘tack_on’ => 1,
‘no_value’ => ‘None’,
‘no_value_link’ => ”
);
$r = wp_parse_args( $args, $defaults );
$term = get_terms($taxonomy);
$output = ‘<li> ‘ . $r['title_li'] . ‘ <ul>’;
if ( $r['tack_on'] ) {
foreach ($_GET as $key => $value) {
if ($key != “C” && $key != $taxonomy) { // We don’t want duplicates of our taxonomy
if ( $querystring ) $querystring .= ‘&’;
$querystring .= $key.”=”.$value;
}
}
}
if ( ! $_GET[$taxonomy] ) {$a = ‘current_item’;} else {$a = ”;}
if ( $querystring ) {
$output .= ‘<li><a title=”‘ . $r['no_value'] . ‘” href=”‘ . get_bloginfo(url) . ‘/?’ . $querystring . ‘”>’;
} else {
$output .= ‘<li><a title=”‘ . $r['no_value'] . ‘” href=”‘ . get_bloginfo(url) . ‘/’ . $r['no_value_link'] . ‘”>’;
}
$output .= $r['no_value'] . ‘</a></li>’;
foreach ($term as $current) {
if ( $_GET[$taxonomy] == $current ) {$a = ‘ current_item’;} else {$a = ”;}
if ( $querystring ) {$b = ‘&’; } else {$b = ”;}
$output .= ‘<li><a title=”‘ . $current->name . ‘” href=”‘ . get_bloginfo(url) . ‘/?’ . $querystring . $b . $current->taxonomy . ‘=’ . $current->slug . ‘”>’;
$output .= $current->name;
$output .= ‘</a></li>’;
}
$output .= ‘</ul></li>’;
// $output=apply_filters( whatever_you_want, $output);
if ( $r['echo'] ) {
echo $output;
} else {
return $output;
}
}