Community Documentation

Display a list of (x) most recent blog entries

Last updated August 8, 2008. Created by Dublin Drupaller on May 19, 2005.
Edited by add1sun, pwolanin. Log in to edit this page.

PLEASE NOTE: The php snippets are user submitted and it is impossible to check every one, so use at your own risk. For users who have setup drupal using an alternate database to the default, please note that the snippets may contain some database queries that may or may not work.

<?php
/**
* The following displays a list of the 10 most recent blog titles
* as links to the full blogs. If you want to increase/reduce
* the number of titles displayed, simply change $listlength value.
*
*/
$listlength="10";
$nodetype="blog";
$output = node_title_list(db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = '%s' AND n.status = 1 ORDER BY n.created DESC"), $nodetype, 0, $listlength));
print
$output;
?>

This can be extended to use the pager, like so.

<?php
$listlength
="10";
$nodetype="blog";
$output = node_title_list(pager_query(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.type = '%s' AND n.status = 1 ORDER BY n.created DESC"), $nodetype$listlength));
$output .= theme('pager', NULL, $listlength);
print
$output;
?>

About this page

Drupal version
Drupal 4.7.x, Drupal 5.x, Drupal 6.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.