how to use views to display taxonomy vocabulary list
knowledg3 - May 29, 2009 - 04:54
hi, i'm creating a classified site (similar to craigslist) and i need to configure a view so that when the user loads up the homepage. a list of individual tables display each taxonomy vocabulary name and list terms displayed in list format. so that if the user clicks the list term it takes them to a page displaying associated content. Could someone point me in the right direction? thanks
example would be [vocabulary:state]
1. Florida [link to display sub list[cities]]
[vocabulary:for sale]
1. cars+trucks [link to display cars+trucks classifieds]

This should be no problem,
This should be no problem, using views in combination with the Insert view module (for showing a views inside nodes).
A scetchy writeup on how I would do it (supposes your're using Views 2.x):
After installing the insert view module mentioned above, and enabled the filter which comes with it the input format you're using (Under Administer > Settings > Input formats, and clicking "configure" on the actual input format, and checking the "insert view" checkbox) you should be able to show the term listings using the following syntax:
[view:the_name_of_your_view==vid]
...where "vid" is the id of the vocabulary you want to show.
(You can figure out vocabulary id's on "Administer > Content > Taxonomy" and then watching the URL:s when hovering over "edit vocabulary" for the different vocabularies. The URL:s contain the vocabulary id, the vid.
Samuel
Samuel Lampa - (Drupal Theme design at http://rilnet.com)
thanks
thanks that really helped allot. one more question if you don't mind?
So, are you saying with the
So, are you saying with the above I can create a structure like so:
Vocabulary: “Industry”
“Industry” has a list of terms on the right sidebar utilizing the taxonomy block module.
The terms can be “Automotive,” “Education,” “Electronics,” “Entertainment,” “Retail,” and so forth.
A hypothetical user is interested in reading user-created reviews about hotels.
He clicks on “Entertainment”
An entirely new page is displayed with all of “Entertainment’s” child terms like so:
Page Title: Entertainment
Terms: Concerts, Movies, Sporting Events, Vacations.
He clicks on “Vacations”
An entirely new page is displayed with all of “Vacations’” child terms like so:
Page Title: Vacations
Terms: Cruiselines, Hotels, Resorts.
He clicks on “Hotels”
An entirely new page is displayed with all of “hotels’” child terms like so:
Page Title: Hotels
Terms: Four Seasons, Hilton, Peninsula, Ritz-Carlton.
He clicks on “Ritz-Carlton”
An entirely new page is displayed with all “Ritz-Carlton’s” locations (actually, Ritz-Carlton’s child terms) like so:
Page Title: “Ritz-Carlton”
Terms: California, Illinois, Massachusetts, New York.
He clicks on “California”
An entirely new page is displayed with all of “California’s” child terms that are also associated with “Ritz-Carlton” like so:
Page Title: “Ritz-Carlton – California”
Terms: Dana Point, Half Moon Bay.
He clicks on “Dana Point”
All the nodes that are tagged with “Dana Point” from the “Hotels’” hierarchical line will now appear.
Node Title: “The Ritz-Calrton in Dana Point is the best.”
Details, details, details.
Node Title: “Awesome stay at the Ritz-Carlton in Dana Point.”
Details, details, details.
I’ve tried so many different things to get such a page structure but nothing yet. Everytime a user clicks on a parent term or a child term, the links return a page that doesn’t filter the contents by the their respective terms, in and of themselves. It returns a ton of teasers that are difficult for users to find what they actually want. For example, when a user clicks on the term “Hotels,” he will get an absorbitant amount of nodes that absolutely had to be tagged with “Hotels” because “Hotels” is the parent term. Rather, the lineage should be like the above page structure so he can see and get what he is actually seeking.
No with what he presented it will not work the way u want it to
Yes sorry the above view structure that he presented won't solve that particular problem it will only create a view of list terms for the top level and its child terms (because they all have the same vid).I have the same problem in sense that I only want to create a structured tree view with links, where it only shows links in order like such
1: First view shows top level terms (parents)
2. Second view shows child terms (child's)
3. 3rd view shows child terms (if present) or associated content (nodes)
if you have any luck with this type of "structured tree view", please let me know of your solutions. But currently the one posted above will only show a view of all vocabulary terms for that ID.
I need that too
azwildcat, I need a nav structure exactly like the one you describe. If you figure out how to do it I'd love to know.
I'm so tired of trying to do
I'm so tired of trying to do this, I'd pay someone who knows to do it.
WILL PAY $
Me too
venusrising
Do it with views
use this code with tid argument and provide default argument with some php code given below. make note of you $vid.
Geshan
My Blog
My Drupal site
Views will only get you part way there
Problem is that the taxonomy module overrides views for individual term pages. So one needs to add code to template.php in addition to the view.
Make a view that has a filter equal to your desired vid, and add an argument for "Parent term". We'll name the view "parent_child_tax".
I embed the view 'parent_child_tax' within a node template file ('node-page.tpl.php') so i can wrap it accordingly and therefore not need to add page display for the view. Inside 'node-page.tpl.php' exists the following code:
<?php
// $title of course is just the value entered in the title field for the designated node.
switch ($title) {
case 'My Parent Categories':
// an argument of 0 finds all terms with no parent term - yielding a list of parents
print views_embed_view('parent_child_tax', 'defaults', 0);
break;
}
?>
Inside template.php add the following:
function mytheme_taxonomy_term_page($tids, $result) {$output = '';
// Only display the description and/or children if listing a single term.
if (count($tids) == 1) {
$term = taxonomy_get_term($tids[0]);
$description = $term->description;
if (!empty($description)) {
$output .= '';
$output .= filter_xss_admin($description);
$output .= '';
}
$parent_object_array = taxonomy_get_parents($tids[0]);
if (!$parent_object_array) { //Its has no parent so display children via view
$output .= views_embed_view('parent_child_tax', 'defaults', $tids[0]);
}
}
return $output;
}
Note that this code only gives you the terms not associated nodes and only works on 2 levels of taxonomy. Probably easy to add another view for the nodes. You might want to also do your breadcrumbs better - in which case consider checking out taxonomy breadcrumbs module or when its ready the new custom breadcrumbs module that will support taxonomy.
Also you can manipulate the breadcrumb right inside the mytheme_taxonomy_term_page function above - just insert code like
<?php$raw_breadcrumb = drupal_get_breadcrumb();
//insert symbols link into the breadcrumb array
$new_breadcrumb = array_merge(array_slice($raw_breadcrumb, 0, 1), array('<a href="/dream-symbols-and-definitions">Symbols</a>'), array_slice($raw_breadcrumb, 1));
drupal_set_breadcrumb($new_breadcrumb);
?>
For a none views-based solution that handles more than two levels and allows for collapsible categories see: http://drupal.org/node/623644
Ok
Been following this one, this seems like a real "goodie" any chance of a visual example (ie a working demo)? Just for the benifit of us old guys?
Well after implementing the 2
Well after implementing the 2 level taxonomy code directly above, i started over and opted for a unlimited level collapsible fieldset approach. I made a link to a demo page which you can find after the code on this page - > http://drupal.org/node/623644
I think such a navigation
I think such a navigation structure should be in the core. This structure I'm trying to implement is the same exact one used in craigslist-the drill down approach.
If i'm not wrong
I think this module does exactly what you need: http://drupal.org/project/vocabindex