“Latest Post” Drupal Block

May 31, 2008 by hejian

Latest Posts dupal block:

$nlimit = 10;
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.status = 1 ORDER BY n.created DESC"), 0, $nlimit);
while ($node = db_fetch_object($result)) {
$output .= node_view(node_load(array('nid' => $node->nid)), 1);
}
print $output;

Just display the list:

print node_title_list($result);

In specific node type:

$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n WHERE n.status = 1 AND n.type = 'type' ORDER BY n.created DESC"), 0, $nlimit);

In specific category:

$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n INNER JOIN {term_node} tn ON n.vid = tn.vid WHERE n.status = 1 AND n.type = 'type' AND tn.tid = n ORDER BY n.created DESC"), 0, $nlimit);

User’s recent post:

if (arg(0) == 'user' && is_numeric(arg(1)) && arg(1) > 0) {
......
$uid = arg(1);
$result = db_query_range(db_rewrite_sql("SELECT n.nid, n.title, n.created FROM {node} n INNER JOIN {users} u ON n.uid = u.uid WHERE n.status = 1 AND n.uid = $uid ORDER BY n.created DESC"), 0, $nlimit);
......
}

Leave a Reply

You must be logged in to post a comment.

Wordpress template made by HeJian