Needs review
Project:
Taxonomy Navigator
Version:
5.x-1.3
Component:
Code
Priority:
Normal
Category:
Feature request
Assigned:
Reporter:
Created:
20 Mar 2009 at 21:59 UTC
Updated:
7 Sep 2009 at 17:29 UTC
Jump to comment: Most recent file
I found it useful to allow for both the vocabulary ID and the term ID to be custom placed in the specified path for a block. This allows my views to be setup with both vocab and term arguments placed where I need them.
Now I can set my "base path" as follows:
/view/myview/%vid%/%tid%
If the %tid% is left off, the module reverts to it's original functionality of appending the term ID to the end.
I tweaked the source code to do accomplish this:
function taxonomy_navigator_block_content($vid) {
$terms = taxonomy_get_tree($vid, 0, -1, 1);
$base_path = variable_get('taxonomy_navigator_base_path_' . $vid, 'taxonomy/term/');
$links = array();
foreach($terms as $term) {
$href1 = str_replace("%tid%", $term->tid, $base_path);
$href2 = str_replace("%vid%", $vid, $href1);
// If the taxonomy ID replacement didn't happen, just append the taxonomy ID.
if (strcmp($base_path, $href1) == 0) {
$href2 = $href2 . $term->tid;
}
$links[$term->tid] = array(
'title' => $term->name,
'href' => $href2,
);
if(taxonomy_navigator_is_term_active($vid, $term->tid)) {
$links[$term->tid]['attributes'] = array('class' => 'active');
}
}
return theme('links', $links, array('class' => 'menu'));
}
I think others would find this useful too, so please consider incorporating this into the source. Thanks!
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | taxonomy_navigator-5.x-1.2_21Mar09.tar_.gz | 8.29 KB | mgenovese |
| #1 | taxonomy_navigator-5.x-1.2_20MAR09.tar_.gz | 8.15 KB | mgenovese |
Comments
Comment #1
mgenovese commentedI have also modified the code to enable vocabulary terms to be pulled from existing nodes versus from the entire list of vocab terms available. This is very useful for views. For example, if my view is only showing nodes of type X, listing all the vocabulary's terms in the Taxonomy Navigator could produce many instances where clicking will produce no results. Thus, I created the option in the block config to only select terms from nodes of a certain content type. This means that the only terms to be shown will come from actual published nodes of a given content type.
This could be expanded to cover multiple content types, instead of the single selector I have implemented. However, this is good enough for the time being.
Comment #2
mgenovese commentedThe above attachment had a bug. Use this one instead.
Comment #3
nestor.mata commentedImplemented in version 5.x-1.3.
Ready for testing.
Thanks a lot for your code