Community Documentation

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

Last updated October 18, 2011. Created by pobster on November 9, 2005.
Edited by MGParisi, ronald_istos, webchick, Heine. Log in to edit this page.

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');

Page status

About this page

Drupal version
Drupal 4.6.x, Drupal 4.7.x
Audience
Themers

Archive

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