- This topic has 9 replies, 4 voices, and was last updated 1 year, 3 months ago by
Ying.
-
AuthorPosts
-
June 2, 2022 at 3:40 pm #2241854
Gian
Hi,
I’m using the following snippet
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">%3$s<a href="https://www.viaggiaregratis.eu/gianluca-orlandi" title="%1$s" rel="author"><span class="author-name" itemprop="name">%2$s</span></a></span>', 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( 'categories', ); } ); add_filter( 'generate_post_date_output', function( $output, $time_string ) { printf( '<span class="posted-on">%s</span> ', $time_string ); }, 10, 2 );
in order to display Author name | date on Archive pages and blog posts like this https://imgur.com/a/Fh47Q4D
Now let’s say that I’d like to display also the category meta next to the date Author name | date | category only on Archive pages and not single blog posts, is it possible?
I’ve tried to implement the code here https://generatepress.com/forums/topic/display-category-meta-next-to-date/ but is not working properly.
Thank you in advance!
June 3, 2022 at 1:06 am #2242118Fernando Customer Support
Hi Gian,
Can you try modifying your PHP to something like this?:
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">%3$s<a href="https://www.viaggiaregratis.eu/gianluca-orlandi" title="%1$s" rel="author"><span class="author-name" itemprop="name">%2$s</span></a></span>', 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( 'categories', ); } ); add_filter( 'generate_post_date_output', function( $output, $time_string ) { printf( ' | <span class="posted-on">%s</span> ', $time_string ); $categories_list = get_the_category_list( ', ' ); if ( $categories_list ) { echo ' | <span class="categories">' . $categories_list . '</span>'; } }, 10, 2 );
Kindly let us know how it goes!
June 3, 2022 at 7:04 am #2242420Gian
Hi Fernando,
Thank you for your reply, it’s almost perfect but as you can see from the link provided in the private information tab there’s a double | | between the author name and the date, do you know how to fix it?
I’m also using this CSS:
.entry-meta { font-size: 13px; } .entry-meta > *:last-child:first-child { border-left: 0; padding-left: 0; margin-left: 0; } .byline img { width: 25px; height: 25px; border-radius: 50%; position: relative; vertical-align: middle; margin: 0 10px 0 0; }
Thank you in advance.
June 3, 2022 at 11:12 am #2242733Ying
StaffCustomer SupportHi there,
You also have this CSS:
.comments-link, .posted-on { border-left: 1px solid #ddd; padding-left: 10px; margin-left: 10px; }
Just remove
border-left: 1px solid #ddd;
from the above CSS.June 3, 2022 at 1:22 pm #2242826Gian
Hi Ying,
it’s working, thank you for your help!
One last thing, if I remove the author name through Appearance > Customize > Layout > Blog > Archive, is there a way to remove the vertical bar only on archive pages https://imgur.com/a/TMADJR8 ?
Thank you in advance.
June 3, 2022 at 4:18 pm #2242916Leo
StaffCustomer SupportAny chance you would consider creating a block element post meta template for this?
https://docs.generatepress.com/article/block-element-post-meta-template/Then there should be no PHP and CSS required at all.
June 3, 2022 at 4:26 pm #2242921Gian
Hi Leo,
I know, that should be easier, but I didn’t switch to Gutenberg yet and I was trying to find a different solution.
June 4, 2022 at 11:07 am #2243566Ying
StaffCustomer SupportYou can change this PHP code
add_filter( 'generate_post_date_output', function( $output, $time_string ) { printf( ' | <span class="posted-on">%s</span> ', $time_string ); $categories_list = get_the_category_list( ', ' ); if ( $categories_list ) { echo ' | <span class="categories">' . $categories_list . '</span>'; } }, 10, 2 );
to:
add_filter( 'generate_post_date_output', function( $output, $time_string ) { if(is_single()) { printf( ' | <span class="posted-on">%s</span> ', $time_string ); } if(! is_single()) { printf( ' <span class="posted-on">%s</span> ', $time_string ); } $categories_list = get_the_category_list( ', ' ); if ( $categories_list ) { echo ' | <span class="categories">' . $categories_list . '</span>'; } }, 10, 2 );
June 5, 2022 at 8:16 am #2244251Gian
Thank you!
June 5, 2022 at 11:18 am #2244352Ying
StaffCustomer SupportNo problem 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.