Latest Blog Entry from Selected Users
PLEASE NOTE! The following snippet is user submitted. Use at your own risk! For users who have setup drupal using an alternate database to the default (MYSQL), please note that the snippets may contain some database queries specific to MYSQL.
The request was I'm trying to make a 'dynamic' page... i.e., with 5 bloggers of my choice, and the last blog post by each.. The result was the following, which you'd place in a page and would act as a normal list of entries (like the main page or a taxonomy listing). The code uses the default node view that your theme defines, but it is flexible enough to be tweaked as a block or something entirely different.
<?php
// code by morbus [at] disobey [dot] com
//
// this is only three users, but you get the idea. the LIMIT 100 at the
// end speeds up the PHP foreach loop so that we don't have to process
// thousands of entries just to find a user who last updated long ago.
// be sure to change the "1, 2, 3" at the end to match your user IDs.
$results = db_query('SELECT nid, uid, created FROM {node} n WHERE n.type = "%s" AND (n.uid = %d OR n.uid = %d OR n.uid = %d) ORDER BY created DESC, uid LIMIT 100', "blog", 1, 2, 3);
//
// once we've displayed this many users, we stop
// processing the rest of our database results.
$num_users = 3;
//
// when we've displayed a user's latest blog post successfully,
// we'll throw 'em in here to remind us we don't need 'em anymore.
$displayed_users = array();
//
// loop through each result.
while ($result = db_fetch_object($results)) {
//
// if we've already displayed this user's latest post,
// we don't need to process any of his earlier ones.
if (isset($displayed_users[$result->uid])) { continue; }
//
// load and display the node. here, we're using a standard
// node theming display, but you can print any custom output
// with $node->teaser, $node->body, and so forth.
$node = node_load(array('nid' => $result->nid));
print node_view($node, 1);
//
// with the node printed, we can flag this user as seen.
$displayed_users[$result->uid] = 1;
//
// if the number of displayed users is the same as the number
// of users we care about, we can break outta the loop.
if (count($displayed_users) == $num_users) { break; }
}
?>