Display rating of node, where is displayed read more

2ge - October 3, 2005 - 10:24
Project:Voting
Version:HEAD
Component:Code
Category:task
Priority:normal
Assigned:Unassigned
Status:needs review
Description

Hi,

I needed display user(s) rating for node, on preview node (it looks like: "Posted in Action | add new comment | read more | 8 reads »", so it will look like "Posted in Action | add new comment | read more | 8 reads | rating: 2.00 »"
So here is code:
- open modules/voting/voting.module
- add:

<?php
/**
* Implementation of hook_link().
*/
function voting_link($type, $node = 0, $main = 0) {
 
$links = array();
  if (
$type == 'node') {
   
$rating = db_fetch_array(db_query('SELECT sum(vote)/count(content_id) as rating from votes where content_id = %d', $node->nid));
    if (
$rating) $links[] = $rating['rating'] ? "rating: " . $rating['rating'] : "rating: no votes";
  }
  return
$links;
}
?>

- save file

Ofcourse there should be nice configuration for module within admin->settings->voting, if display this, or not, but this maybe next time :) (it is not big issue)

Enjoy

#1

Dabitch - September 20, 2007 - 20:18

"from votes" - don't you mean "from node_voting"...?

#2

Dabitch - September 20, 2007 - 20:20

Spoke too soon, I guess I'm just wondering which table(s) you're gathering this from? I think It's a cool idea.

 
 

Drupal is a registered trademark of Dries Buytaert.