Display the (x) most recent nodes in full from a specific category

This info is likely outdated

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;
?>

 

How would this be converted

chromatic - June 6, 2005 - 04:43

How would this be converted to show teasers? I'd like to show a taxonomy and the teaser portion of the post. Also, the fact that it's themed actually kind of messes up my design because it nests something in something that looks just like it... if that makes sense. Is there a way to get the omit the theme() portion of this and still display it?

any update?

karmalarm - June 23, 2005 - 07:19

I'd also like to see that, moreover, with a link to the full post - any ideas

This might help

robertgarrigos - June 24, 2005 - 23:20

This is something I'm using in my personal page (www.garrigos.org) to show a portion of the post that it might help you

 

<?php
unset ($output);
$taxo_id = 1;
$list_no = 5;
$sql = "SELECT node.title, node.nid, node.created, node.body 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_no";
$output .= "<ul>";
$result = db_query($sql);
while ($anode = db_fetch_object($result)) {
$created = format_date($anode->created, $type = 'small', $format = '', $timezone = NULL);
$output .= "<li>".l($anode->title, "node/$anode->nid")." ($created)";
$output .= "<br><small>".substr($anode->body,0,250)."...</small></li>";
}
$output .= "</ul>";
print $output;
?>

 

This shows up the last 5 post to taxonomy term num. 1 with a portion (250 char.) of the body.

Not quite complete

merlinofchaos - July 2, 2005 - 19:32

There's one important thing missing from this code snippet, which is the username. If you use this snippet (at least with 4.6) you might notice that it always lists the submissions as by 'Anonymous'.

For my purposes, I modifed the query to include "SELECT * FROM node, users" and the WHERE clause includes "node.uid = users.uid". That fixed that small problem.

Also note that $TEASER = true makes it show only the teaser, whereas $TEASER = false makes it show the actual entry.

Tags: Drupal