Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save evandonovan/435024 to your computer and use it in GitHub Desktop.
Save evandonovan/435024 to your computer and use it in GitHub Desktop.
<?php
// convenience theming function for taxonomy lists -- ead 6.10.10
function taxonomy_node_list_terms_by_vocabulary($nid, $voc_id, $link = FALSE, $ul = FALSE) {
/* loads a "dummy" node in order to use taxonomy_node_get_terms_by_vocabulary()
to get an array of taxonomy terms */
$node = new stdClass();
$node->vid = db_result(db_query("SELECT MAX(vid) FROM {node_revisions} WHERE nid = %d", $nid));
$terms = taxonomy_node_get_terms_by_vocabulary($node, $voc_id);
if(!isset($terms) || !is_array($terms) || empty($terms)) { return ''; }
// collects terms by name from the taxonomy term array
$term_names = array();
foreach($terms as $term) {
$term_names[$term->name] = $term->name;
$term_names_linked[] = l($term->name, taxonomy_term_path($term), array('attributes' => array('class' => 'taxonomy-term')));
$term_names_links['taxonomy-term-' . $term->tid] = array('title' => $term->name, 'href' => taxonomy_term_path($term));
}
// outputs terms in unordered list
if($ul) {
if($link) {
$term_list = theme_links($term_names_links);
}
else {
$term_list = theme_item_list($term_names, NULL, 'ul', array('class' => 'taxonomy-term'));
}
}
// outputs terms in comma-delimited list
else {
if($link) {
$term_list = implode(', ', $term_names_linked);
}
else {
$term_list = implode(', ', $term_names);
}
}
// only return a $term_list if it doesn't have the empty UrbanMinistryBloggers tag in it
// note use of ternary operator (http://php.net/manual/en/language.operators.comparison.php)
$ret = (strpos($term_list, '/taxonomy/term/13797') === FALSE) ? $term_list : '';
return $ret;
}
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment