6

How do I get a user's profile path in Drupal based on the author of the current node?

<?php print t('Posted on !date by !username', array('!username' => theme('username', $node), '!date' => format_date($node->created,'custom','m.d.y'))); ?>

The above gets me the right url, but that's all i want... the url.

Matt Ryan
  • 1,717
  • 2
  • 20
  • 30

1 Answers1

8

$link = drupal_get_path_alias('user/' . $node->uid);

At least I think that's the most direct. I'm sure there's a more correct answer though.

Chuck Vose
  • 4,560
  • 24
  • 31
  • Also, I think in your theme templates $author is available directly. – Chuck Vose Sep 24 '10 at 20:38
  • i wasn't able to get the author var but, get_path_alias was exactly what i was looking for thank you! – Matt Ryan Sep 24 '10 at 20:48
  • 4
    If you're using this to link to the user page (the common use case), you can skip drupal_get_path_alias and just pass the user/# path to l (http://api.drupal.org/api/function/l/6), which will convert it to the alias for you. – Scott Reynen Sep 25 '10 at 03:51
  • 2
    And if you don't need the full link with l(), just url() will get it for you as well. $link = url('user/22323'); – rfay Jul 13 '13 at 23:36