开发者

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.


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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜