Display the (x) most recent nodes in full from a specific category
Last modified: January 8, 2007 - 22:13
Note from the moderator: Thank you for sharing the snippet with the Drupal community. In its current state the snippet might present security risks. See Writing secure code for a background on the most common mistakes.
Specifically, the snippet
- does not check output, potentially allowing Cross Site Scripting attacks (XSS, see How to handle text in a secure fashion for more information).
- bypasses node access restrictions; Use db_rewrite_sql.
Using node_view, instead of theme('node') prevents xss via the teaser and would also allow image nodes to work.
PLEASE NOTE! The following snippet is user submitted. Use at your own risk! For users who have setup Drupal using an alternate database to the default (MySQL), please note
that the snippets may contain some database queries specific to MySQL.
<?php
/**
* This php snippet displays the most recent node in full
* from a specific category
*
* To increase/decrease the number of nodes listed
* change the $list_length value to suit.
*
* Works with drupal 4.6.x & 4.5.x
*
* Snippet submitted by Robert Garrigos (robertgarrigos)
*/
$taxo_id = 10;
$list_length = 1;
$sql = "SELECT * FROM node INNER JOIN term_node ON node.nid = term_node.nid WHERE term_node.tid = $taxo_id ORDER BY node.created DESC LIMIT $list_length";
$result = db_query($sql);
while ($anode = db_fetch_object($result)) {
$output .= theme('node', $anode, $teaser = TRUE, $page = FALSE);
}
print $output;
?>
subscribe
subscribe