bimbom22
bimbom22

Reputation: 4510

Drupal Get Nodes by Author ID

Is there a function in the Drupal API that I can use to get nodes by author ID?

I am trying to create a block that shows the current user a list of their authored pages and I'm having a surprisingly difficult time with it.

Upvotes: 3

Views: 5596

Answers (2)

ceejayoz
ceejayoz

Reputation: 180023

You could be using the Views module for this. It generates pages, blocks, feeds, and more via a web UI that lets you construct a database query. Very slick, and heavily used on most Drupal sites.

Upvotes: 10

googletorp
googletorp

Reputation: 33275

This is easily done with SQL:

global $user;
$items = array();
$result = db_query("SELECT nid, title FROM {node} WHERE uid = %d", $user->uid);
while ($row = db_fetch_object($result)) {
  $items[] = l($row->title, 'node/' . $row->nid);
}
return theme('item_list', $items, NULL, 'ul');

The above code in a custom block should do the trick. Just remember not to cache it.

Upvotes: 2

Related Questions