Menu theming
| Project: | Taxonomy context |
| Version: | 5.x-1.x-dev |
| Component: | User interface |
| Category: | feature request |
| Priority: | normal |
| Assigned: | Unassigned |
| Status: | active |
Jump to:
I've had to use taxonomy_context in such a way that each category has its own style, and to do so I've had to alter the module itself. I think it would be useful if either
a) the menu items had unique classes (by $tid would be easiest), or
b) the menu element generation code was themable.
The first one is easiest and most straightforward, and would only require the following changes:
<?php
$output .= '<li class="expanded">'. $link ."\n";
?><?php
$output .= '<li class="expanded taxonomy-context-'.$term->tid.'">'. $link ."\n";
?>and
<?php
$output .= '<li class="collapsed">' . $link . "</li>\n";
?><?php
$output .= '<li class="collapsed taxonomy-context-'.$term->tid.'">' . $link . "</li>\n";
?>The second solution is perhaps more drupally, and would involve lifting some or all of the menu_tree code out into a themable function. As some brief off-the-cuff starter code, maybe the following would work:
<?php
/**
* Return a menu tree for a vocabulary.
*/
function taxonomy_context_menu_tree($vid, $tid = NULL) {
static $context;
if (!isset($context)) {
$context = taxonomy_context_get_context();
}
$parents = array();
$parents_terms = array_reverse(taxonomy_get_parents_all($context->tid));
foreach ($parents_terms as $parent) {
$parents[] = $parent->tid;
}
$terms = $tid ? taxonomy_get_children($tid, $vid) : taxonomy_get_tree($vid, 0, -1, 1);
$output = "<ul class=\"menu\">\n";
if ($terms) {
foreach ($terms as $term) {
$output .= theme('taxonomy_context_menu_item',$vid,$term,$parents);
}
}
$output .= "</ul>\n";
return $output;
}
function theme_taxonomy_context_menu_item($vid,$term,$parents) {
$params = array('title' => $term->description ? strip_tags(node_teaser($term->description)) : t('View this section'));
$link = l($term->name, taxonomy_term_path($term), $params);
if (in_array($term->tid, $parents)) {
$output .= '<li class="expanded">'. $link ."\n";
$output .= taxonomy_context_menu_tree($vid, $term->tid, FALSE) ."\n";
if (variable_get('taxonomy_context_node_block', TAXONOMY_CONTEXT_NODE_BLOCK_NONE)) {
$output .= '<ul class="menu">'. taxonomy_context_show_nodes($term->tid) ."</ul>\n";
}
$output .= "</li>\n";
}
else {
$output .= '<li class="collapsed">' . $link . "</li>\n";
}
return $output;
}
?>I'd maybe expand that to include a theme_menu_tree style function - basically taking <ul class=\"menu\"> out of the function and wrapping it around the output with a themable function - but I'm afraid I'm strapped for time right now.
Apologies for not doing a patch file, I haven't got the facility to do so at the moment... hope it is useful nonetheless.

#1
Hi,
Very much interested in theming a specific menu-item in a vocabulary block with this great module. Somebody experience with the above, and is there a possibility this will be put into the module?
Thanks a lot for considering this.
Greetings,
Martijn