Community Documentation

Display all recent posts except "node type X" and "node type Y"

Last updated December 19, 2007. Created by ericatkins on January 4, 2007.
Edited by add1sun. Log in to edit this page.

I needed a block to post all recent posts except "project issues" and "events". See the modified code below to see how I did it. The code can easily be changed to show all content except other node types.

<?php
//how many of the last results in the db will we grab
   
$num_nodes = 7;

//get all nodes except the project_issue or event nodes
   
$result = db_query_range(db_rewrite_sql('SELECT n.nid, n.title, n.type
    FROM {node} n
    WHERE n.status = 1 AND n.type <> "project_issue" AND n.type <> "event"
    ORDER BY n.changed DESC'
), 0, $num_nodes); //order by the date/time they were posted or changed


//format the $result and only leave the node titles, then place it in the $output variable
   
$output = node_title_list($result);
   
$output .= l('More...', 'tracker');

//obvious
   
print $output;
?>

Code author Oculus at http://hushedcasket.com

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