By hruodland on
The recent content block lists the most recently changed nodes. I'd rather have a block that lists the most recently created ones, and would prefer not to install an additional module or two to do so.
In Drupal 6 the following code worked:
$sql = "SELECT node.title, node.nid FROM node WHERE node.promote = 1 ORDER BY node.nid DESC LIMIT 5";
$output .= "<ul>";
$result = db_query($sql);
while ($anode = db_fetch_object($result)) {
$output .= "<li>".l($anode->title, "node/$anode->nid")."</li>";
}
$output .= "</ul>";
return $output;
It's broken in 7.0, I suppose partly because db_fetch_object is gone. I'm a php ignoramus--can anyone suggest how to fix it?
[UPDATE: I seem to have achieved my goal by changing the line
->orderBy('changed', 'DESC')
in node.module to
->orderBy('created', 'DESC')
It's line 2193 in the 7.0 version of the module. I suppose I'd rather have a php snippet for a block but I'll go with this unless something else turns up]
Comments
I think you would have better
I think you would have better luck with Views & a block display from that view. IMHO, it's better than having raw PHP code in a block if it can be avoided.
Danny Englander | Twitter | Instagram