Daily most favorite nodes block

jango - October 21, 2006 - 23:37
Project:Favorite Nodes
Version:5.x-1.x-dev
Component:Code
Category:feature request
Priority:normal
Assigned:jango
Status:active
Description

A block to show nodes that are added to users' favorites in last 24 hours, would be great.

#1

JordanD - September 17, 2007 - 15:30
Version:4.7.x-1.x-dev» 5.x-1.x-dev

If I could get a daily/weekly (Or even configurable time frame?) most favorited nodes block---I'd be happier than a pig in mud. Any chances?

#2

asund - January 22, 2008 - 20:18

I really want this feature!
Pretty please? =)

#3

asund - May 3, 2008 - 00:32

I wrote a similar snippet here. Might be able to use it for this with a few tweeks
http://drupal.org/node/215210#comment-830015

#4

asund - May 3, 2008 - 20:04

Okay, I rewrote it to be a list of the most favorited for the last days.
This can just be pasted in a block with PHP filter.

<?php
//You may make som changes to these variables:
$days = 7; //Number of days to include
$list_length = 10; //Number of nodes to list
$min_faves = 1; //Minimum amount of favorites to be listed

//---------------
$result = db_query("SELECT * FROM {node} WHERE created > %d-86400*%d",time(),$days); //Gets all nodes from the specified days

while ($anode = db_fetch_object($result)) {
 
$sql = "SELECT nid FROM {favorite_nodes} WHERE nid = $anode->nid"; //Counts number of favorites for each node
 
$count = db_num_rows(db_query($sql, $nid));
  if(
$count>=$min_faves){
   
$favnodes[$anode->nid]=array("count" => db_num_rows(db_query($sql, $nid)), "nid" => $anode->nid); //Stores data in an    Array
 
}
}

rsort($favnodes); //Sorts nodes by number of favorites
$output = "<ul>";
$prcnt = 0;
while(
$prcnt<$list_length){
 
$node = node_load($favnodes[$prcnt]["nid"]); //Loads node from nid
 
if($node){
   
$output .= "<li><a href='".url(drupal_get_path_alias("node/".$node->nid))."'>".$node->title."</a></li>";
  }
 
$prcnt++;
}
$output .= "</ul>";
print
$output;
?>

 
 

Drupal is a registered trademark of Dries Buytaert.