This piece of code is to generate a menu or list of links to taxonomy pages. I used it inside a block. I created a view that shows all items under certain taxonomy term.
It is basically a taxonomy menu but you can customized an place it anywhere.
Good link to learn more about embedding your own views: http://groups.drupal.org/node/10129
<?php
$vid = 6; // this is the vocabulary id
$parent = 1679; // this is the parent term
$taxo_tree = taxonomy_get_tree($vid, $parent, $depth = -1, $max_depth = 1);
$items = array();
foreach($taxo_tree as $term){
// This is a better way to get all the nodes under a term, including nodes tagged with child terms.
$count = taxonomy_term_count_nodes($term->tid, $type = 0);
if($count){
$items[] = array("data" => l($term->name, "taxonomy/term/".$term->tid)." [$count]");
}
}
print theme_item_list($items, $title = NULL, $type = 'ul', $attributes = NULL);
?>
Hi,
it's really useful for me as an example of working with views 2,
but I'm sorry I don't understand necessity of views here.
For counting nodes we can use function taxonomy_term_count_nodes.
Thank you so much for your comment. I didn't know there was a
taxonomy_term_count_nodes
function in the API. This makes a lot more sense. I was using the views because I thought it was a good way to get all the nodes including the child nodes, but with the function that you just suggested it is less code and I guess less php processing.
Thanks again.
The article you posted about telemarketing tips are of great help. Thanks for sharing it. I can feel that through this the number of my clients will increase. Keep it up buddy. Read on for more about telemarketing at www.mgupload.org
Kenny
www.mgupload.org
I'm impressed. You're truly well informed and very intelligent. You wrote something that people could understand and made the subject intriguing for everyone. I'm saving this for future use.
Vivian
Marks Web
www.imarksweb.net
You must be aware that you really have an awesome site. Does exactly what it sets out to do. Stimulating me to read much more of your post. Hope to see a lot more excellent posts from you shortly. Keep it up buddy.
Raine
InfoTech
www.shabsoft.net
I’m impressed. Very informative and trustworthy blog does exactly what it sets out to do. I’ll bookmark your weblog for future use.
Joseph
www.joeydavila.com
Your online Library
Brilliant work! The comprehensive data delivered was extremely helpful. I really hope you carry on with the great work succesfully done.
Milwaukee Garage Door
Plumbing San Bernardino CA
Chelmsford Locksmith
Salt Lake City Garage Door
Locksmiths Nashville TN
Locksmiths Fountain Valley CA
Roofers Largo
Post new comment