Community Documentation

Display body from most recent nodes

Last updated April 21, 2012. Created by Folkert on June 12, 2006.
Edited by richardhayward, pwolanin, Heine. Log in to edit this page.

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.

This snippet will display the full body from a specified number of the the most recent nodes of a specified type.

<?php
/* create only the body of the last node(s) specified by '$is_node_type' and '$list_nr'
* works with category module enabled in 4.7.2
*/
$is_node_type = "page";
$list_nr = 5;
$sql = "SELECT n.nid, n.vid, n.type, n.created, r.body, r.format FROM {node} n INNER JOIN {node_revisions} r ON r.vid = n.vid WHERE n.type = '%s' ORDER BY n.created DESC";

$result = db_query_range(db_rewrite_sql($sql), $is_node_type, 0, $list_nr);

while (
$node = db_fetch_object($result)) {
 
// print your markup here
 
print check_markup($node->body, $node->format, false);
}
?>

About this page

Drupal version
Drupal 4.7.x

Reference

Drupal’s online documentation is © 2000-2012 by the individual contributors and can be used in accordance with the Creative Commons License, Attribution-ShareAlike 2.0. PHP code is distributed under the GNU General Public License. Comments on documentation pages are used to improve content and then deleted.
nobody click here