- This topic has 18 replies, 3 voices, and was last updated 3 years, 9 months ago by Leo.
-
AuthorPosts
-
May 16, 2020 at 6:01 am #1287065Benjamin
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
May 16, 2020 at 6:05 am #1287071BenjaminI 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; }
May 16, 2020 at 2:51 pm #1287805TomLead DeveloperLead DeveloperHi 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 π
May 17, 2020 at 1:02 am #1288219BenjaminThat worked. Thanks π
May 17, 2020 at 9:44 am #1288862TomLead DeveloperLead DeveloperYou’re welcome π
May 30, 2020 at 4:25 am #1307469BenjaminHi,
I actually noticed a problem with the code you gave me.
It adds the date twice in archives:
The date shows up both under each post title, and under the excerpt.
Any idea how to fix it?
Thanks
May 30, 2020 at 6:22 am #1307536DavidStaffCustomer SupportHi 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', ); } );
June 4, 2020 at 9:07 am #1314451BenjaminYes, I did but deleting it solved my problem. Thanks! π
June 4, 2020 at 10:08 am #1314538DavidStaffCustomer SupportGlad to hear that
June 25, 2020 at 7:14 am #1341397BenjaminHi,
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 π
June 25, 2020 at 8:37 am #1341656DavidStaffCustomer Supporttry unchecking Display comment count in Customizer > Layout > Blog
June 25, 2020 at 8:42 am #1341662BenjaminI tried that but it deletes the comment count everywhere (including single posts.)
June 25, 2020 at 1:30 pm #1341908LeoStaffCustomer SupportJust 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 π
June 25, 2020 at 1:43 pm #1341925BenjaminNo, 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.
June 25, 2020 at 2:07 pm #1341955LeoStaffCustomer SupportSorry what code are you still using?
Can you activate the comments so I can see the issue?
-
AuthorPosts
- You must be logged in to reply to this topic.