开发者

Drupal Get Nodes by Author ID

开发者 https://www.devze.com 2023-01-04 01:40 出处:网络
Is there a function in 开发者_运维问答the Drupal API that I can use to 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

精彩评论

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