[Support request] Problem adding author picture under blog post title

Home Forums Support [Support request] Problem adding author picture under blog post title

Home Forums Support Problem adding author picture under blog post title

Viewing 15 posts - 1 through 15 (of 19 total)
  • Author
    Posts
  • #1287065
    Benjamin

    Hi,

    I’m trying to add the author picture under the blog post title in single posts so I used the follow code:

    add_filter( 'generate_post_author_output', function() {
        return sprintf( ' <span class="byline">%1$s</span>',
            sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
                esc_html( get_the_author() ),
                get_avatar( get_the_author_meta( 'ID' ) )
            )
        );
    } );
    
    add_filter( 'generate_header_entry_meta_items', function() {
        return array(
            'author',
            'comments-link',
            'date',
        );
    } );
    
    add_filter( 'generate_footer_entry_meta_items', function( $items ) {
        return array(
            'date',
            'categories',
        );
    } );

    It worked but it added the pictures in blog archives as well. How can I only add the pictures in single posts?

    Another problem I run into is that the comment count doesn’t appear. So I added this code:

    .single .comments-link {
        display: inline-block;
    }

    Is this the right way to do it?

    Thanks

    #1287071
    Benjamin

    I forgot to say I also added the following CSS to style the author picture (and show the last updated date instead of the published date:

    .posted-on .updated {
         display: inline;
     }
     .posted-on a time:nth-child(2) {
         display: none;
     }
     .posted-on a time:first-child:before {
         content: "Updated: ";
     }
     .posted-on a time:last-child:before {
         content: "Published: ";
     }
    
    .byline img {
        width: 35px;
        height: 35px;
        border-radius: 50%;
        position: relative;
        vertical-align: middle;
        margin: 0 10px 0 0;
    }
    
    .comments-link,
    .posted-on {
    	border-left: 1px solid #ddd;
    	padding-left: 10px;
    	margin-left: 10px;
    }
    #1287805
    Tom
    Lead Developer
    Lead Developer

    Hi there,

    Try this for your first function instead:

    add_filter( 'generate_post_author_output', function( $output ) {
        if ( ! is_singular() ) {
            return $output;
        }
    
        return sprintf( ' <span class="byline">%1$s</span>',
            sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<a href="%1$s" title="%2$s" rel="author"><span class="author-name" itemprop="name">%3$s</span></a></span>',
                esc_url( get_author_posts_url( get_the_author_meta( 'ID' ) ) ),
                esc_attr( sprintf( __( 'View all posts by %s', 'generatepress' ), get_the_author() ) ),
                esc_html( get_the_author() ),
                get_avatar( get_the_author_meta( 'ID' ) )
            )
        );
    } );

    That comments CSS is the correct way to make it show up at the moment πŸ™‚

    #1288219
    Benjamin

    That worked. Thanks πŸ™‚

    #1288862
    Tom
    Lead Developer
    Lead Developer

    You’re welcome πŸ™‚

    #1307469
    Benjamin

    Hi,

    I actually noticed a problem with the code you gave me.

    It adds the date twice in archives:

    https://growwithless.com/

    The date shows up both under each post title, and under the excerpt.

    Any idea how to fix it?

    Thanks

    #1307536
    David
    Staff
    Customer Support

    Hi there,

    do you still have this or similar function that uses the generate_footer_entry_meta_items filter applied?

    add_filter( 'generate_footer_entry_meta_items', function( $items ) {
        return array(
            'date',
            'categories',
            'post-navigation',
        );
    } );
    #1314451
    Benjamin

    Yes, I did but deleting it solved my problem. Thanks! πŸ™‚

    #1314538
    David
    Staff
    Customer Support

    Glad to hear that

    #1341397
    Benjamin

    Hi,

    I used the codes you gave me but now the comment count shows up twice for every post on the archive page:

    https://growwithless.com/blog/

    Any idea what’s causing this?

    Thanks πŸ™‚

    #1341656
    David
    Staff
    Customer Support

    try unchecking Display comment count in Customizer > Layout > Blog

    #1341662
    Benjamin

    I tried that but it deletes the comment count everywhere (including single posts.)

    #1341908
    Leo
    Staff
    Customer Support

    Just to confirm, so you want to show comment count in single posts but not in archives?

    If so can you activate the option again we will need to use some CSS to hide it in archives.

    Let me know πŸ™‚

    #1341925
    Benjamin

    No, I would like to show it in both :). But it’s showing twice in archives. And if I deactivate comments count via the customizer, it disappears everywhere.

    #1341955
    Leo
    Staff
    Customer Support

    Sorry what code are you still using?

    Can you activate the comments so I can see the issue?

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