[support] create block of recent blog posts by one user?

Kitt Hodsden kitt-drupal at hodsden.org
Mon Jan 29 03:00:33 UTC 2007


I recognize this problem has been solved for the poster of the original 
question, but I want to strongly suggest that this option not be used for others 
who may be considering it.

My reasons include:

The SELECT query here ignores any unpublished nodes (needs a "AND published = 
1").

The SELECT query will show the first 10 posts, not the last 10 (needs a DESC 
after the "ordered by created").

The query also assumes the tables have no prefixes, but I'll assume anyone who 
uses it can adjust that value.

Similary, the query might assume MySQL with the limit, depends on whether or not 
you use an offset.  It isn't cross DB safe (db_query_limit might have been 
better).

The block also cannot be later edited by any user who doesn't have the PHP input 
filter permission (any saved edits will revert to a filter HTML by default).

But the real, most important reason I think it's questionable is because it 
doesn't include any way to check the user reading the post has permissions to 
read the content the title will link to.  Even if the title is all the user 
without permissions can see, showing a link without access to the main content 
is bad practice.  Some permission checking modules (og, node_privacy_by_role 
(for < Drupal 5)) need the db_rewrite_sql hook calls to limit what nodes are 
being displayed based on role, node type or other permission limits.

Yes, it is possible to construct a query that handles all of these issues.  
Instead of such a query, I highly recommend using the views module, as others 
have suggested, to minimize the need to worry about them, or any other issues 
that might arise (like the PHP filter requirement).

Kitt.
 

> Create a custom block with input format "PHP" with PHP code in it that
> looks something like this:
> 
> <?php
> $result = db_query("SELECT nid, title, uid, '' FROM node WHERE uid =
> ## AND type = 'blog' ORDER BY created LIMIT 10");
> 
> $content = node_title_list($result, "Joe Bob's Blog");
> echo $content;
> ?>
> 
> You'll need to change ## to the numeric user id of the user's blog you
> want.




More information about the support mailing list