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

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

 
 

Drupal is a registered trademark of Dries Buytaert.