By davide1982 on
Hello everybody! I'm using the following snippet to display list of tags by number of nodes attached to them:
-------------------
unset ($output);
$vocabulary_id = 1;
$result = db_query
("SELECT d.tid, d.name, MAX(n.created) AS updated, COUNT(*) AS count FROM {term_data} d INNER JOIN {term_node} USING (tid) INNER JOIN {node} n USING (nid) WHERE d.vid = $vocabulary_id AND n.status = 1 GROUP BY d.tid, d.name ORDER BY count DESC, d.name");
$items = array();
while ($category = db_fetch_object($result)) {
$items[] = l($category->name .' ('. $category->count .')', 'taxonomy/term/'. $category->tid) .'<br />';
}
print theme('item_list', $items);
-----------------------------
Above code helps me to show the full list of Tags sorted by Count of nodes. How should I make it to show only Top 5 items of the list ?
Your help is much appreciated !
Comments
Change db_query to db_query_range
Your call then would be
See: db_query_range()
THANKS
That helped! Thank you so much!!