Created
September 23, 2011 08:18
-
-
Save tung/1236951 to your computer and use it in GitHub Desktop.
Tag list block for Drupal 6.x
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Abstraction-breaking custom tag lister. | |
* This block lists all tags under the given taxonomy vocabulary, | |
* in order of frequency, and then name. The tags are hyperlinked. | |
*/ | |
$vocabulary_id = 8; | |
$cutoff = 15; // don't show results that don't pass the threshold | |
$threshold = 5; // after cutoff, don't show tags with counts less than this | |
$tag_query = "SELECT td.tid, td.name, COUNT(DISTINCT tn.nid) as num " . | |
"FROM term_data td, " . | |
" term_node tn " . | |
"WHERE td.vid = %d AND " . | |
" td.tid = tn.tid " . | |
"GROUP BY td.tid, td.name " . | |
"ORDER BY num DESC, td.name ASC "; | |
$result = db_query($tag_query, $vocabulary_id); | |
if ($result) { | |
print "<div class=\"item-list\">"; | |
print "<ul>"; | |
$results_so_far = 0; | |
while ($row = db_fetch_object($result)) { | |
$results_so_far++; | |
if ($results_so_far > $cutoff && $row->num <= $threshold) | |
break; | |
print "<li>" . | |
"<a href=\"/site/taxonomy/term/" . $row->tid . "\">" . | |
$row->name . | |
"</a>" . | |
" (" . $row->num . ")" . | |
"</li>"; | |
} | |
print "</ul>"; | |
print "</div>"; | |
} else { | |
print "Tags unavailable."; | |
} | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment