• Resolved Houdini

    (@romariokg)


    Hello, how can I display the first and last name separately in the “Seller Information” block on the ad page?

    In the file “seller-info.php” PHP code: <?php $listing->the_author(); ?> displays the first and last names together. How can I display them separately?

    I need to make it so that the full name is displayed, and only the first letter of the last name is displayed. For example: If the username is Ali Akbar, I need the output to appear as: Ali A.

    Thanks!

Viewing 6 replies - 1 through 6 (of 6 total)
  • Plugin Support Ali Akbar Reyad

    (@alireyad)

    Hi,
    As by default, you can not show in this way. You have to customize code to display in this way.

    What you can do –

    1. Create user object.
    2. Then retrieve first name and last name from object
    3. Then modify last name as your requirements.
    $authorData  = get_user_by( 'id', $listing->get_author_id() );
    $firstName = $authorData->first_name;
    $lastName = $authorData->last_name;
    $first_character = substr($lastName, 0, 1);

    Thank you

    Thread Starter Houdini

    (@romariokg)

    Hello, friend! It didn’t work, or I’m doing something wrong! Could you give me a ready-made code that I can paste into the seller-info.php file?

    Thank you

    Plugin Support Ali Akbar Reyad

    (@alireyad)

    Hi,
    It works but not sure where you placed it. Which theme are you using?

    Thank you

    Thread Starter Houdini

    (@romariokg)

    Hi, use the “Classilist” template. Please write the working code and the path in which file to use it.

    Plugin Support Ali Akbar Reyad

    (@alireyad)

    Hi,
    May be overridden the file from theme. Please, create ticket from our site for premium products.

    Thank you

    Thread Starter Houdini

    (@romariokg)

    This solution helped me. Maybe it will be useful to someone else, I’ll leave it here:

    <?php $authorData = get_user_by( 'id', $listing->get_author_id() );
    if ( $authorData ) {
    $firstName = $authorData->first_name;
    $lastName = $authorData->last_name;
    echo esc_html( $firstName ) . ' ';
    if ( ! empty( $lastName ) ) {
    $first_character = mb_substr( $lastName, 0, 1 );
    if ( ! empty( $first_character ) ) {
    echo esc_html( $first_character ) . '.';
    }
    }
    } else {
    echo 'No user info.';
    }
    ?>


Viewing 6 replies - 1 through 6 (of 6 total)
  • You must be logged in to reply to this topic.