Pedro Posada | Create list of links to taxonomy terms

Create list of links to taxonomy terms

Posted on March 7, 2009 - 5:43pm
<< 25 of 54 >>

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);
?>

 

Submitted by Julia (not verified) on March 8, 2009 - 2:18am.

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.

Submitted by pedro on March 8, 2009 - 2:47am.

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.

 

Submitted by Kenny (not verified) on February 22, 2011 - 1:41am.

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

Submitted by Books and Manuals (not verified) on February 27, 2011 - 7:17pm.

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

Submitted by InfoTech (not verified) on March 4, 2011 - 5:56pm.

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

Submitted by Your online Library (not verified) on August 21, 2011 - 7:39pm.

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

Submitted by qdfoxe964 (not verified) on September 30, 2011 - 4:18am.

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

The content of this field is kept private and will not be shown publicly.
CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
Copy the characters (respecting upper/lower case) from the image.