Drupal - Show the taxonomy in the format - "term(node count)" - for a given vocabulary


/ Published in: Other
Save to your folder(s)



Copy this code and paste it in your HTML
  1. <h4>Tags</h4>
  2. <ul>
  3. <?php
  4. $vid = 1;
  5. $vocab = taxonomy_get_tree($vid);
  6.  
  7. $terms = array();
  8. foreach ($vocab as $key=>$value) {
  9. $count = db_result(db_query("SELECT COUNT(nid) as count FROM {term_node} WHERE tid = %d", $vocab[$key]->tid));
  10. print '<li><a href="/'.drupal_get_path_alias('taxonomy/term/'.$vocab[$key]->tid).'">'.$vocab[$key]->name.'</a> ('.$count.')</li>';
  11. }
  12. ?>
  13. </ul>

Report this snippet


Comments

RSS Icon Subscribe to comments

You need to login to post a comment.