By default Drupal can list out all blog entries of a particular user,

1. but will that be possible if I want to have, say, all story nodes contributed by a particular user? (and vice versa)

2. furthermore is it possbile to list out all nodes (regardless of types) contributed by a particular user?

Can the default Drupal do this? Or if I need some extension modules?

Thanks a lot!

Comments

Anonymous’s picture

You can do this fairly easily with a php snippet on a page. Here's a sample snippet to get you started:


$user = arg(2);
$type = arg(3);

if (!empty($user)) {
   if (!empty($type)) {
      $where = "and n.type = '$type'";
   }
   $result = pager_query(db_rewrite_sql("select n.nid, n.created from {node} n, users where n.status = 1 and n.uid = users.uid and users.name = '$user' $where order by n.created ASC"));
   while ($node = db_fetch_object($result)) {
      $output .= node_view(node_load(array('nid' => $node->nid)), 1);
   }
   print $output;
} else {
   print "No user specified";
}

Create a new node of the type page, and select PHP Code for the format, and paste this in. There ya go. To use it, just go to the node and add on a username and optionally a node type. Example, if you are using clean URL's:

node/thisnodeid/username/story

would list all the nodes of type story by user 'username'.

Or you could just do

node/nodeid/username

and list all nodes by username of any type.

adolg’s picture

I tried this, but regardless of the parameters it always shows some 9 items of content, always the same ones

Dublin Drupaller’s picture

Hi Adolg,

Try some of the sliced bread snippets in the Drupal Handbook.

there's a few variations of "listing nodes created by a certain user" there. The snippets in there are tested so they should work for you.

Dub

Currently in Switzerland working as an Application Developer with UBS Investment Bank...using Drupal 7 and lots of swiss chocolate