1. Add the following function in your theme template.php
function <theme>_get_user_nodes_count($uid) {
$query = db_select('node', 'n');
$query->condition('uid', $uid, '=');
$query->condition('status', '1', '=');
$query->addExpression('COUNT(1)', 'count');
$result = $query->execute();
if ($record = $result->fetchAssoc())
return $record['count'];
return 0;
}
2. So you could retrieve the node count by calling
<theme>_get_user_nodes_count($uid)
If you only want to count the number of nodes of a specific content type use the following piece of code in template.php instead
function <theme>_get_user_nodes_count($uid) {
$query = db_select('node', 'n');
$query->condition('type', '<content-type>', '=');
$query->condition('uid', $uid, '=');
$query->condition('status', '1', '=');
$query->addExpression('COUNT(1)', 'count');
$result = $query->execute();
if ($record = $result->fetchAssoc())
return $record['count'];
return 0;
}
Done =)
Next: Drupal 7 – Get the number of comments by user
Reference: Drupal Forum – Post count (x)/comment count (x) on user profile page
Pingback: Drupal 7 – Get the number of comments by user | Eureka!