Syndicate

Feed

Who authored this node?

Say we have a node ID (nid), and we want to know who authored the Drupal node with that ID, and that author is not currently the user that’s logged-in, then we use the Drupal function node_load(). (The companion function to user_load()). The function node_load() either accepts a numerical value which is the nid of the node, OR it accepts an associative array containing information about the node, criteria against which the function will try to find a match, in the database. The function returns a node object. One property of this object is uid, that is, the user ID of the author of the node, and another is name, and that's the name of the author. Say we want to find the e-mail address of the author of node with node ID 25:

/* Using node_load with a node ID parameter */
$node = node_load(25);
/* Then using user_load with the user ID */
$user = user_load(array('uid' => $node->uid));
print t('You may e-mail @name at !mailURL.',  array(
  '@name' => $user->name,
  '!mailURL' => l($user->mail, 'mailto:' . $user->mail),
  )
);
Last edited by Caroline Schnapp about 7 weeks ago.

Comments

Drupal Goddess

You are a god damned Drupal Goddess... I throw digital flowers at your feet. Your tutorials have taught me more in five minutes than three months of stumbling through the drupal.org forums.

In the lots of cases Drupal

In the lots of cases Drupal site sux(( Users ask same questions from year to year, no good FAQ or standard tutorials (how to make catalog using taxonomy for example...) That's why I love blogs like 11heavens :)

Post new comment

The content of this field is kept private and will not be shown publicly.
  • Web page addresses and e-mail addresses turn into links automatically.
  • Lines and paragraphs break automatically.
  • You may post code using <code>...</code> (generic) or <?php ... ?> (highlighted PHP) tags.
  • Allowed HTML tags: <a> <b> <i> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <sup> <sub> <dd> <del> <blockquote> <img> <q> <p> <div>

More information about formatting options

CAPTCHA
This question is for testing whether you are a human visitor and to prevent automated spam submissions.
1 + 13 =
Solve this simple math problem and enter the result. E.g. for 1+3, enter 4.