[Resolved] Elements – Author PHP won't display

Home Forums Support [Resolved] Elements – Author PHP won't display

Home Forums Support Elements – Author PHP won't display

Viewing 6 posts - 1 through 6 (of 6 total)
  • Author
    Posts
  • #1035542
    Dwayne
    <p>This post was written by <?php the_author(); ?> - The Author.</p>
    <?php echo get_avatar( get_the_author_meta( 'ID' ));?>

    I can’t figure out why I can’t get an output. Neither of those will work. I’m just trying to display the author name so that I can style it.
    Displaying other post data (title, meta, etc) work just fine.
    I’m sure I’m missing something obvious.

    The above first line just outputs as:

    “This post was written by – The Author.”

    The second line just outs the default avatar.

    I’m using the ‘HOOK’ element. I have ensured that “Execute PHP” is checked.
    I’m using a modified version of the ‘Merch’ template.

    Thanks for any info!

    #1035716
    David
    Staff
    Customer Support

    Hi there,

    which Hook are you using ?

    #1036810
    Dwayne

    Hi,

    Was attempting various. I want it to display ‘after_header’ – and I was just adding to the “Single Post Entry Header” element that is added by the Merch template. That template already displays the title, categories, date.

    Seems to only work if the HOOK selected is after_main_content or later?

    #1037117
    David
    Staff
    Customer Support

    Yeah those functions only work within the loop or inside the post content. Try this instead:

    <?php 
    global $post; 
    $author_id=$post->post_author;
    $author_name = get_the_author_meta( 'display_name', $author_id );
    $author_avatar = get_avatar( $author_id, 50 ); 
    
    printf( '<span class="hero-byline">This post was written by %1s</span><span class="hero-avatar">%2s</span>',
        $author_name,
        $author_avatar
    );
    
    ?>
    #1037348
    Dwayne

    Yes! the layout here was throwing me for a …loop.

    On a (related) note, a slight typo on the doc for ‘removing author’ from a page in the Documentation:

    https://docs.generatepress.com/article/generate_post_author_output/#remove-from-post-type

    It should say “Another example is if you want to remove the AUTHOR on a specific post type, but keep it elsewhere”

    #1037359
    David
    Staff
    Customer Support

    Glad to be of help – and thanks for pointing out the typo! We’ll get that fixed asap

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