Forums

[resolved] $comment->user_id Nice name instead of ID? (5 posts)

  1. richarduk
    Member
    Posted 2 years ago #

    How can I change if ($comment->user_id) {$user=$comment->user_id; echo $user} to output a nice name instead of the ID?

    I've tried using $user_identity but haven't been able to get it to work.

    Basically if the commenter was a registered user I want to output their name on the comment.

    Any help, please? :-)

  2. vtxyzzy
    Member
    Posted 2 years ago #

    This should do what you want:

    if ($comment->user_id) {$userdata=get_userdata($comment->user_id); echo $userdata->display_name}

  3. richarduk
    Member
    Posted 2 years ago #

    Worked like a dream! Many thanks!

    For anyone else, there's missing semi-colon :-)

    <?php if ($comment->user_id) {$userdata=get_userdata($comment->user_id); echo $userdata->display_name;}?>

  4. vtxyzzy
    Member
    Posted 2 years ago #

    Glad it worked! Now, please use the dropdown at top right to mark this topic 'Resolved'.

  5. richarduk
    Member
    Posted 2 years ago #

    Woops!

    Forgot :-)

Topic Closed

This topic has been closed to new replies.

About this Topic