Display Flag count

<?php
/**
* Implements hook_node_view_alter()
*/
function flag_alter_node_view_alter(&$build) {
//print_r($build[‘links’][‘flag’][‘#links’][‘flag-like’][‘title’]);
if (isset($build[‘links’][‘flag’][‘#links’][‘flag-like’])) {
//find out the number of bookmarks for this node
$node_id = $build[‘body’][‘#object’]->nid;
//todo
// fid should not be hard coded
$results = db_query(“SELECT count FROM {flag_counts} WHERE content_type =’node’ AND content_id = :nid AND fid = ‘3’”, array(‘:nid’=>$node_id));
foreach ($results as $record) {
$result = $record->count;
}
if (empty($result)) {
$result = 0;
}
$build[‘links’][‘flag’][‘#links’][‘flag-like’][‘title’] .= “($result)”;
}
}

In the reference example we have D6 code.

 

Advertisements