- This topic has 29 replies, 5 voices, and was last updated 1 year, 9 months ago by Ying.
-
AuthorPosts
-
May 3, 2022 at 7:18 pm #2208439Fernando Customer Support
Hi Rupert,
Yes, the code is still working. Just tested it now to be sure as well.
To confirm, have you added a custom field to the post as mentioned by David and Tom above?
Example: https://share.getcloudapp.com/WnuyvDN0
Moreover, have you replaced
your_coauthor_custom_field_name
andyour_coauthor_link_custom_field_name
with the ones you set when creating the custom field?Here it is working on my end: https://share.getcloudapp.com/X6uE1Qox
Hope this clarifies. Kindly let us know. 🙂
May 4, 2022 at 9:30 am #2209307RupertHey Fernando,
Thanks so much for your response!
I did some testing and the code does indeed work, but it doesn´t seem to be compatible with the gravatar code snippet that I´m using …
Is there any way to combine the two (i.e., display the gravatar and also ‘fact checked by co-author’) or is this now outside your remit?
Here´s the code in question –
add_filter( ‘generate_post_author’, ‘__return_false’ );
add_filter( ‘generate_show_comments’, ‘__return_false’ );
add_filter( ‘generate_post_date_output’, ‘tu_fancy_byline’ );
function tu_fancy_byline( $date ) {
printf( ‘ <span class=”byline”>%1$s</span>’,
sprintf( ‘<span class=”author vcard” itemtype=”http://schema.org/Person” itemscope=”itemscope” itemprop=”author”>%4$s<span class=”author-name” itemprop=”name”>%3$s</span></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’ ) )
)
);May 4, 2022 at 10:24 am #2209366YingStaffCustomer SupportHi Rupert,
Try replace your currentcode with the blow code:
add_filter( 'generate_post_author', '__return_false' ); add_filter( 'generate_show_comments', '__return_false' ); add_filter( 'generate_post_date_output', 'tu_fancy_byline' ); function tu_fancy_byline( $date ) { printf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person” itemscope="itemscope" itemprop="author">%4$s<span class="author-name" itemprop="name">%3$s</span><span class="coauthor" itemprop="name">Fact checked by: %5$s</a></span></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' ) ), get_post_meta( get_the_ID(), 'your_coauthor_custom_field_name', true ) ) );}
May 4, 2022 at 10:39 am #2209392RupertHey Ying!
That works perfectly. The only thing is that there are now no links to the respective ‘author pages’.
Also, would it be possible for the code to only take effect on certain posts … I know it´s a bit of a long shot 🙂
Thanks so much for the rapid response!
May 4, 2022 at 11:15 am #2209427YingStaffCustomer SupportIn your original code, I don’t see a link has been added to the author name, so would you like to add links to the author or the coauthor?
If to the author, is the link author archive?
If to the coauthor, is the link set in custom field?
And when you say certain posts, what are the conditions of those posts?
If it gets too complicated, I would strongly recommend using
block element - post meta template
: docs.generatepress.com/article/block-element-post-meta-template/May 4, 2022 at 11:46 am #2209453RupertHey Ying,
Yes, you´re right. You could click on the author´s name and it´d take you to their post archives though.
If possible I´d like to link both author and coauthor to the about page (via a deep link if possible). The coauthor link is set in custom field but I´m not sure what you mean by the author archive link.
Let´s forget about customizing certian posts, I´m basically looking for the simplest solution without having to add unnecessary plugins to my website 🙂
Thanks so much for your help!
May 4, 2022 at 12:44 pm #2209502YingStaffCustomer Supportauthor archive link
It’s the default link of an author name, it’s an archive page shows all the articles that this author published.
I´d like to link both author and coauthor to the about page
The about page is a static page? I don’t see a way to call it in the code for the author, unless you can add the about link to each author’s profile at dashboard > users > webiste.
If that can be done, you can use the below code to call the website set for the author:
add_filter( 'generate_post_author', '__return_false' ); add_filter( 'generate_show_comments', '__return_false' ); add_filter( 'generate_post_date_output', 'tu_fancy_byline' ); function tu_fancy_byline( $date ) { printf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<span class="author-name" itemprop="name"><a href="%7$s">%3$s</a></span><span class="coauthor" itemprop="name">Fact checked by: <a href="%6$s">%5$s</a></span></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' ) ), get_post_meta( get_the_ID(), 'your_coauthor_custom_field_name', true ), get_post_meta( get_the_ID(), 'your_coauthor_link_custom_field_name', true ), get_the_author_meta( 'user_url' ) ) );}
May 4, 2022 at 1:01 pm #2209522RupertPerfect, that works really well for the coauthor.
I think I´m just going to link to my author archive for the sake of simplicity. How do I do so?
Thanks so, so much 🙂
May 4, 2022 at 1:29 pm #2209550YingStaffCustomer SupportIn that case, this will be the final code 🙂
add_filter( 'generate_post_author', '__return_false' ); add_filter( 'generate_show_comments', '__return_false' ); add_filter( 'generate_post_date_output', 'tu_fancy_byline' ); function tu_fancy_byline( $date ) { printf( ' <span class="byline">%1$s</span>', sprintf( '<span class="author vcard" itemtype="http://schema.org/Person" itemscope="itemscope" itemprop="author">%4$s<span class="author-name" itemprop="name"><a href="%1$s">%3$s</a></span><span class="coauthor" itemprop="name">Fact checked by: <a href="%6$s">%5$s</a></span></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' ) ), get_post_meta( get_the_ID(), 'your_coauthor_custom_field_name', true ), get_post_meta( get_the_ID(), 'your_coauthor_link_custom_field_name', true ), ) );}
May 4, 2022 at 1:56 pm #2209570RupertThank you so, so much, Ying.
It´´s very much appreciated!
May 4, 2022 at 2:05 pm #2209576YingStaffCustomer SupportYou are welcome 🙂
July 15, 2022 at 4:24 pm #2284012ChintanHi
I want to add another author to my blog posts as well and link their names to their author pages.
So I named this second author “Editor” by adding a custom field, but I had no luck with seeing another author appear in my posts. Can you please help me with the PHP code that I need to add from this forum post? Also, I am probably not adding the custom field properly, so if there’s a link you can please direct me to for understanding how to do it, would be great!
Grateful for the help 🙂
July 15, 2022 at 6:29 pm #2284050YingStaffCustomer SupportThe easiest solution would be using
block element - post navigation
:
https://docs.generatepress.com/article/block-element-post-navigation/You don’t need PHP code for it.
The headline block of GB can pull the value from custom fields.
Since it’s a resolved topic, if you can’t get it work, please open a new topic!
July 16, 2022 at 8:19 am #2284566ChintanAwesome thanks I managed to use dynamic post meta to achieve this the way you mentioned above 🙂 I’ll add a new topic with a few questions I have!
July 16, 2022 at 11:11 am #2284652YingStaffCustomer SupportGlad that you’ve got it sorted! Good job 🙂
-
AuthorPosts
- You must be logged in to reply to this topic.