By mabster on
I have created another block for my site, so I thought I'd post it here in case anyone was interested.
It shows the last 3 blog entries for each of the last 3 users who have posted blogs.
So not only does it show you some recent blogs, it also encourages people to blog more often (to get their name pushed up the list).
It's relatively simple to change it to show the last x entries by the last y users.
Anyway, here's the code:
global $user;
if (user_access("access content")) {
$blogs = "";
$queryResult = db_query_range("SELECT n.uid, u.name, max(n.nid) FROM {node} n INNER JOIN {users} u ON u.uid = n.uid WHERE n.type = 'blog' AND n.status = 1 GROUP BY n.uid, u.name ORDER BY 3 DESC", 0, 3);
while ($node = db_fetch_object($queryResult)) {
$blogs .= l(t("<h3>%username</h3>", array("%username" => $node->name)), "blog/$node->uid", array("title" => t("Read %username's latest blog entries.", array("%username" => $node->name))))
. node_title_list(db_query_range("SELECT n.title, n.nid FROM {node} n WHERE n.type = 'blog' AND n.status = 1 AND n.uid = " . $node->uid . " ORDER BY n.nid DESC", 0, 3));
}
return $blogs
. "<div class=\"more-link\">". l(t("more"), "blog", array("title" => t("Read the latest blog entries."))) ."</div>";
}
Comments
Thanks for posting mabster.
Thanks for posting mabster. I've been trying to figure out how to do something very close to this. What I would like to do is to provide a list of blogs (i.e., blog *titles*, not blog entries) in a block. It seems like your code can be tweaked to do this, but I can figure out what to change. I would appreciate any suggestions on how to modify your code to do this. Thx,
Donovan.
"It always seems impossible, until it is done."
- Nelson Mandela
You mean a list of users who
You mean a list of users who have blogs?
Hmmm. Your question, just ca
Hmmm. Your question, just caused me to realize that a Blog's title is actually the Blogger's user name. So, that being the case -- yes I'm trying to just get a list of users who have blogs. It would be nice, however, if Blogs could be given a user-determined title and short description upon creation. Any suggestions on either/both are appreciated.
"It always seems impossible, until it is done."
- Nelson Mandela
Agreed, users need to be able to name their blogs
Besides giving users the ability to give their blogs a name, it would be nice to have a pretty URL feature so that we don't have to refer to blogs with '?q=blog/10', etc.
domain.tld/blog/[username]
Enable Clean URLs in configuration (admin/system) and then you get very nice URLs for everything including blogs. (You'll need ModRewrite support. See also the .htaccess file in Drupal's top-level directory.)
Blogs can be reached via uid or user name (blog/[username] or blog/[uid]).
Thx frjo.
Thx frjo.
"It always seems impossible, until it is done."
- Nelson Mandela