Count nodes by content types
Monday, November 9, 2009 - 20:40

The tutorial "Count all nodes" is a great tool if you need statistics displayed on you're site. If you want to specify by content types you can do it like this:

<?php
$mytype = array('you're content type name');
$in = implode("', '", $mytype);
$count = db_result(db_query("SELECT COUNT(DISTINCT(n.nid)) FROM {node} n WHERE n.type IN('$in') AND n.status=1"));
echo "$count";
?>

To enable this, activate the Php Filter from Drupal core modules and create a block with the php-input-filter selected. Works very well, and remember, you can theme this easily to make it look pretty :-)

Comments

Great function, thank you!

Great function, thank you! :-)

Add comment

The content of this field is kept private and will not be shown publicly.