How to split the results into separate pages if the snippet returns lots of results

Last modified: August 27, 2009 - 00:09

Creates a paginated list of node titles of a specific type, within x days of today with a link to each node.

<?php
/**
* Creates a paginated list of node titles of a specific type, within x days of today
* with a link to each node.
*
* To change which type is listed, simply edit the $node_type string.
* To change the amount of results per page, edit the $list_length variable.
*
* This works with both Drupal 4.6 and Drupal 4.7
*/
$node_type = "image";
$time_lapse = strtotime("-50 days");
$list_length = 25;
$start_stamp = date("Y-m-d", $time_lapse);
$end_stamp = date("Y-m-d");
$start_stamp = strtotime($start_stamp);
$end_stamp = strtotime($end_stamp);
$sql = db_rewrite_sql("SELECT n.title, n.nid FROM {node} n WHERE n.created < %d AND n.created > %d AND n.type = '%s'");
$result = pager_query(sprintf($sql, $end_stamp, $start_stamp, $node_type), $list_length);
while (
$anode = db_fetch_object($result)) {
$output []= l($anode->title, "node/$anode->nid");
}
print
theme('item_list', $output);
print
theme('pager', NULL, $list_length);
?>

Same as before, if you wish to give the list a title then change print theme('item_list', $output); into print theme('item_list', $output, 'Node Titles');

 
 

Drupal is a registered trademark of Dries Buytaert.