Vocabulary Term Count with Columns

This is a sample of how to create a list of all terms that are being used from a particular vocabulary (category).

I found 16 terms to put into 2 columns for you.


  • Attendance Matrix
    Attendance Matrix
    (1) - This provides a table view of who attended which meetings.
    Project page | Documentation page | Change log
  • FAQ_Ask
    FAQ_Ask
    (14) - This module is an add-on to the FAQ module that allows users with the 'ask question' permission to create a question which will be queued for an 'expert' to answer.
    Project page | Documentation page | Change log
  • Get_Content_Type
    Get_Content_Type
    (1) - The get_content_type module fills an oversight by the D5 developers. When they moved the part of CCK (sometimes called CCK-Lite) into core for creating new content types, they forgot the analog to taxonomy/term/xxx, that is node/type/xxx. This simple module provides that function.
    This module has not been contributed due to disparaging comments from more advanced Drupallers.
    Project page & Documentation
  • Glossary
    Glossary
    (25) - The glossary module scans content for glossary terms (including synonyms). The glossary indicator is inserted after every found term, or the term itself is turned into an indicator, depending on the site settings. By hovering over the indicator, users will see the definition of that term displayed as a "tool tip." Clicking the indicator leads the user to that term presented within the whole glossary or directly to the detailed description of the term, if available.
    Project page | Documentation | Change log
  • Gotcha
    Gotcha
    (8) - Gotcha intercepts the Contact form submission and checks an inserted hidden field to catch spambots. If something is there, Gotcha simply returns to the front page and ignores the message. The attempt is logged and saved in the database. If the field is empty, then the message is scanned by the Spam module, which has very good filters for catching spam. If everything looks okay, the message is passed on through to the Contact module for normal processing.
    Project page | Documentation | Change log
  • Helpers (8) - Helpers is a collection of functions to help developers work smarter and faster.
    Project page | Documentation page | Change log
  • Longer Titles
    Longer Titles
    (2) - Drupal 6 changed the length of the title field for nodes to 255. This module brings that change to version 5.x.
    Project page | Documentation | Change log
  • Node_Type_Filter
    Node_Type_Filter
    (4) - This is a simple module that allows for various lists, such as "taxonomy/term," to be filtered by content type.
    Project page | Documentation page | Change log
  • Register_Country
    Register_Country
    (1) - Are you creating a country portal or a site dedicated to a specific country?
    The Register Country module is designed to intercept new registrations and check if the IP address being used is registered to a country that the site administrator has chosen. In this way, you may limit sign ups to your site to specific countries.
    Project page | Documentation page | Change log
  • Site Documentation
    Site Documentation
    (39) - To simplify it a bit, the Site Documentation module picks up information from various places within the Drupal environment. Some of the information comes from internal arrays, some is derived from system calls, and some comes directly from the database tables. This information is pulled into a report that can be used to document the site. In addition, it will detect some problems that may exist in your installation, and optionally correct them.
    Project page | Documentation page | Change log
  • Site Notes
    Site Notes
    (14) - SiteNotes introduces a new content type, called, coincidentally, "sitenotes." It also creates a menu item in the Admin » Site building menu, where it's available only to privileged users; it's even protected by Access Control. So now all those little Post-Its™ and other scraps of paper can go right into your database where you can find them again. Create "How To" notes for your users, theme changes, CSS modifications, special code notes, and keep them safe AND available.
    Project page | Documentation | Change log
  • Spam Tokens
    Spam Tokens
    (2) - This add-on module adds another tab to the Spam administration page that allows Spam module administrators to examine and modify the tokens used by the Bayesian filters to determine the probability of content being spam.
    Project page | Documentation | Change log
  • Spam_Tune
    Spam_Tune
    (1) - The Spam_Tune module allows Spam module administrators to examine and modify system variables that are normally just defaulted in the Spam module. These variables are added to the 'Advanced' tab in the Spam settings. This module will probably never be contributed as it can be dangerous to alter the parameters exposed here.
    Project page & Documentation
  • Taxonomy Browser
    Taxonomy Browser
    (8) - Think of this as a 'build your own category view' page. A single page with each term organized nicely by vocabulary. The user selects the terms which she or he wants to see, and then this module constructs the right URL (e.g. taxonomy/view/and/3,4,5) and then displays matching nodes to the user.
    Project page | Documentation page | Change log
  • Taxonomy Delegate
    Taxonomy Delegate
    (1) - This module allows an administrator with "administer taxonomy" permission to delegate the administration of a vocabulary to a non-admin role.
    This module has not yet been contributed. We are looking for beta-testers.
    Project page & Documentation
  • Taxonomy Image (5) - Allow an administrator to associate image with taxonomy terms or vocabularies for display with the terms.
    Project page | Documentation page | Change log

Here's the code.

<p>This is a sample of how to create a list of all terms that are being used from a particular vocabulary (category).</p>
<?php
  $vid = 1; /* <---- put correct vocabulary ID here */
  $num_cols = 2; /* <---- put number of columns here */
  $show_pic = module_exists('taxonomy_image');
  echo '<div class="use-pin">';
  $items = array();
  $terms = taxonomy_get_tree($vid);
  foreach ( $terms as $term ) {
    $count = taxonomy_term_count_nodes($term->tid);
    if ($show_pic) { $pic = taxonomy_image_display($term->tid /*, 'align="left"'*/); }
    else {$pic = NULL; }
    $name_and_count = l($pic . $term->name,'taxonomy/term/'.$term->tid, NULL, NULL, NULL, NULL, TRUE)." (".$count.") - ".$term->description;
    $items[] = $name_and_count .'<div class="clear-block"></div>';
  } /* end foreach */
  if (count($items)) {
    if ($num_cols == 1) {
      echo theme('item_list', $items);
    }
    else {
    $slice = ceil(count($items) / $num_cols);
    echo '<table cellpadding="10"><tr>';
    for ($i = 0; $i < $num_cols; ++$i) {
      $start = $i * $slice;
      $class = $i % 2 ? 'even' : 'odd';
      echo '<td class="'. $class .'" valign="top">';;
      echo theme('item_list', array_slice($items, $start, $slice));
      echo '</td>';
    }
  echo '</tr></table>';
  }
  }
  else { echo 'No terms found'; }
  echo '</div>';
?>

This code is nice, but seems to be listing full nodes

How can I list teasers only.

Thank you

Not nodes

This code lists taxonomy terms, not nodes. The stuff you see above is all part of the term descriptions and Taxonomy Image.

Don't show terms with 0 count

Hi Nancy,

Thank you for providing us with these great scripts!

I have tried the script on this page and it works perfectly, only thing is it also displays empty terms -- is there a way to avoid that?

This script of yours does just that: http://drupal.org/node/146043#comment-234365, using count.

I just don't know how to combine it to make it work... do you have a solution?

Thank you,
Nico

Try this

Right after the line that says $count = taxonomy_term_count_nodes($term->tid); add a line if (!$count) { continue; }

I think that will do it.

It worked perfectly. Again,

It worked perfectly.
Again, thank you so much!

How to display only vocabulary and level 1 terms?

I have put your code and it works perfectly, but how to modify the code, so it will display like this :

I have tree structure category :
AUTOMOTIVE (vocabulary)
** Cars(terms level 1)
***** Mazda (terms level 2)
****** Mitsubishi (terms level 2)
****** Mercedez (terms level 2)
** Motorcycle (terms level 1)
****** Honda (terms level 2)
****** Kawasaki (terms level 2)
****** Yamaha (terms level 2)

and I only need to show like this (vocabulary with level 1 terms):
AUTOMOTIVE (vocabulary)
** Cars (terms level 1)
** Motorcycle (terms level 1)

How to modify the code?
Thank you.

Chris

Hmm...

This is untested, but a pretty good guess. If you test and it works, please let me know and I'll include all this. At the top, include a line:
  $max_depth = 1;
Then look a few lines down for this code:
  $terms = taxonomy_get_tree($vid);
  foreach ( $terms as $term ) {
    $count = taxonomy_term_count_nodes($term->tid);
Change it to this:
  $terms = taxonomy_get_tree($vid);
  foreach ( $terms as $term ) {
    if ($term->depth > $max_depth) { continue; }
    $count = taxonomy_term_count_nodes($term->tid);

Only showing terms level 1 with no vocabulary

I have update the code, and now it only show term level 1 , and vocabulary not showing, any suggestion? Thanks

-Chris-

Yes, change the depth

The line at the top that says "$max_depth = 1;" controls how deep into the vocabulary it will go.

I can't get is works even I

I can't get is works even I changed "$max_depth = 1;" or 2, 3..only shows level 1 terms.