Community Documentation

Display a list of node titles of a specific type, within certain dates/times

Last updated January 8, 2007. Created by pwolanin on June 10, 2005.
Edited by Heine, Dublin Drupaller, punboy@aaron.pu..., moshe weitzman. Log in to edit this page.

Note from the moderator: Thank you for sharing the snippet with the Drupal community. In its current state the snippet might present security risks. See Writing secure code for a background on the most common problems.

Specifically, the snippet

  • bypasses node access restrictions; you should usually pass queries through db_rewrite_sql.

<?php
/**
* Creates a list of node titles of a specific type, within certain dates
* with a link to each node.
*
* To change which type is listed, simply edit the $node_type string.
* To change the starting date, simply change the $start_stamp.
* To change the ending date, simply change the $end_stamp.
*
* This works with Drupal 4.6
*/
$node_type = "image";
$start_stamp = 'June 9 2005';
$end_stamp  = 'June 10 2005';
$start_stamp = strtotime($start_stamp);
$end_stamp = strtotime($end_stamp);

$sql = "SELECT node.title, node.nid FROM node WHERE node.created < $end_stamp AND node.created > $start_stamp AND node.type = '$node_type'" ;
$output .= "<ul>";
$result = db_query($sql);
while (
$anode = db_fetch_object($result)) {
$output .= "<li>".l($anode->title, "node/$anode->nid")."</li>";
}
$output .= "</ul>";
print
$output;
?>

About this page

Drupal version
Drupal 4.6.x

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