How to list most viewed nodes using Statistics module in Drupal 6?

I'm looking for the PHP code to use in a custom theme.

  • You're probably better off using Views, with sorting based on number of hits. Content shouldn't usually be hard-coded into a theme. – naught101 May 16 '13 at 1:50

I should have enabled this feature in admin panel before using the following code:

$number_of_hot = '10';
$hot_result = db_query_range("SELECT nid FROM {node_counter} ORDER BY totalcount DESC", array(), 0, $number_of_hot);
while ($hotid = db_result($hot_result)) {
$hot = node_load($hotid);
print $hot->title;
|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.