What's New block for Drupal

ian – Sun, 2006 – 11 – 26 20:43

I couldn't find an easy way to put a list of the most recent posts in a block in Drupal, so here's some PHP code to do it. Whack this in a PHP block, and you're off. This is what's running on the left-hand side of this site.

Apparently there's some Drupal magic that converts old-style node URLs (http://site/node/1234) into pretty URLs (http://site/this-is-a-story).

<?php
$sql = "SELECT title, nid FROM {node} WHERE promote = 1 ORDER BY created desc limit 10";
$rec = db_query($sql);
$list = array();
while ($obj = db_fetch_object($rec)) {
$path = "node/".$obj->nid;
$list[] = l($obj->title, $path, array(), NULL, NULL, FALSE, TRUE);
}
print theme("item_list", $list);
?>


Reply

Please solve the math problem above and type in the result. e.g. for 1+1, type 2
The content of this field is kept private and will not be shown publicly.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd>
  • Lines and paragraphs break automatically.
More information about formatting options