Content Count by Taxonomy Term

Usage of "Changelogs" Category by Term and Content Type

These are Change log "blogs" for my modules. The module entries (terms) themselves contain links to the appropriate project page, or page on my site, and "Contributed Modules" handbook pages.
Attendance Matrix
This provides a table view of who attended which meetings.
Project page | Documentation page | Change log
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
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
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 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 is a collection of functions to help developers work smarter and faster.
Project page | Documentation page | Change log
Longer Titles
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
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
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
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
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
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
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
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
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
Allow an administrator to associate image with taxonomy terms or vocabularies for display with the terms.
Project page | Documentation page | Change log

And here's the code

  $vid = 1;      // <<--- put correct vocabulary number here
  $vocab = taxonomy_get_vocabulary($vid);
  echo '<h2>Usage of "'. $vocab->name .'" Category by Term and Content Type</h2>';
  if ($vocab->description) { echo '<h6>'. $vocab->description .'</h6>'; }

  $header = array(t('Term'));
  $rows = array();
  $type = array();

  // Build header row with types.
  foreach ($vocab->nodes as $key => $value) {
    $type[] = $value;
    $name = $value;
    $header[] =  array('data' => $name, 'align' => 'right') ;
  } /* end foreach */

  $terms = taxonomy_get_tree($vid);
  foreach ( $terms as $term ) {
    $line = array();
    $line[] = l($term->name, 'taxonomy/term/'. $term->tid) ."<br/><small>". $term->description ."</small>";
    foreach ($type as $content_type) {
      $count = taxonomy_term_count_nodes($term->tid, $content_type);
      if ($count) { /* don't show terms with 0 count */
        $line[] = array('data' => $count, 'align' => 'right');
      } /* end if count */
      else { $line[] = ' '; };
    } /* end each content_type */
    $rows[] = $line;
  } /* end foreach term */

  echo theme('table', $header, $rows);


What about only including published nodes?

This would be a really useful tweak I think: to be able to only include published nodes in the content count.

It does

Taxonomy_term_count_nodes() only counts published nodes.

Thanks! What about sorting, and limiting number?

Thanks for all your snippets. They're really useful.
This list is just what I'm looking for. As an added bonus, is it possible to sort the terms by most used, and to be able to specify a number of terms to list?


Interesting idea. Obviously it is possible because that's sort of what Tagadelic does. I'll have to do some playing around.


I started looking at this, but there's a little snag: While this particular example only shows one content type, it can actually handle multiple content types, so which do you sort on?


I guess you could sort by the total count - all content types combined. What do you think?

Code Error

I get a error with this code:

    * warning: Invalid argument supplied for foreach() in /apps/opt/drupal/includes/ : eval()'d code on line 13.    * warning: Invalid argument supplied for foreach() in /apps/opt/drupal/includes/ on line 813.<

any clues Drupal 5?

Make sure...

Make sure the vocabulary you request (line 2: $vocab = 2;<) has terms defined in it.

how to filter a view by taxonomy term count

i can't believe this is the first time i ran into your website...i had to do this lot of time ago,
anyway, i'm trying to do something simple but i can't find the way,
i would like to give the chance to promote a node to the frontpage to the users, and i thought to use taxonomy to do this.
I might create a vocabulary just with "promote" or "i won't promote this" (i think it's something similar to the old and unmaintained loves and hates module),
and then i might build a view to filter nodes by the term count, using the promote term as the reference.
It seems reasonable,we have tagadelic too and it is using the term count function, i guess, to give a font size to some terms, but there isn't a filter in views using the term recurrence.
So i can't do this and i couldn't find an easy way to get this working.
Any idea?


Views doesn't handle non-node content, so I don't know how this can be done. Sorry.