I'm making a block to be displayed on a node page that I want to display some information about the author of the node. I need to be able to show the number nodes of different types that the author has created. Any suggestions? I found this which gets me halfway there, but I need to be able to filter it by only the node authors content.
1 Answer
The simplest way would be to extend the query from the other question you linked to and add the user id as an extra parameter:
function yourtheme_get_node_count($content_type) {
$query = "
SELECT COUNT(*)
FROM {node} n
WHERE n.type = :type
AND n.uid = :uid";
// Get the node object for the current page.
$node = menu_get_object();
$params = array(':type' => $content_type, ':uid' => $node->uid);
$amount = db_query($query, $params)->fetchField();
return $amount;
}
Be sure to only call this on a node page as menu_get_object()
will only return a node object when you're on such a page.