• Resolved venkmanuk

    (@venkmanuk)


    hi there,

    i’m wondering if anyone fancies sharing a snippet with me that allows me to show the comment author first name & last name. something like:

    if – there’s a First Name & Last Name for logged in author show that
    else – show their nickname
    else – they are a guest so show the name they put into the comment form.

    <?php comment_author(); ?>

    doesn’t cut it.

    I’m using a custom walker to list comments – similar to / based on the one here:
    codex – wp_list_comments

Viewing 4 replies - 1 through 4 (of 4 total)
  • Maybe there is a plugin that will help for you.?

    Thread Starter venkmanuk

    (@venkmanuk)

    hmm, maybe. i’d rather avoid plugins…

    Thread Starter venkmanuk

    (@venkmanuk)

    I might try this, needs tested but

    if ($comment->user_id) {
    $user=get_userdata($comment->user_id);
    $first_name = get_userdata($comment->first_name);
    $last_name = get_userdata($comment->last_name);
    echo $user->$first_name $last_name
    } else { comment_author(); }
    Thread Starter venkmanuk

    (@venkmanuk)

    oh haha that wasn’t ever going to work.

    wrote myself the solution tho! [ Hi-5 !! ]

    it’s in my functions.php file as part of the custom walker mentioned above ^ … i took some pointers on how to find author info from the WP install’s comment-template.php … but really it just came down to a nice little if else deal-y.

    // Avoid just using comment author
    if ( $comment->user_id && $user = get_userdata( $comment->user_id ) ) {
    
    $author = $user->first_name;
    $authorb = $user->last_name;
    $authorn = $user->nickname;
    
    	if ($author||$authorb) {
    		printf( __( '<cite class="fn">%1$s %2$s</cite>' ), $author, $authorb );
    	} elseif ($authorn) {
    		printf( __( '<cite class="fn">%1$s</cite>' ), $authorn );
    	};
    
    } else {
    
     printf( __( '<cite class="fn">%s</cite>' ), get_comment_author() );
    
    };
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘comment author – first name last name or guest name’ is closed to new replies.