[Resolved] Two authors in a single post

Home Forums Support [Resolved] Two authors in a single post

Home Forums Support Two authors in a single post

Viewing 15 posts - 16 through 30 (of 30 total)
  • Author
    Posts
  • #2208439
    Fernando
    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 and your_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. 🙂

    #2209307
    Rupert

    Hey 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&#8221; 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’ ) )
    )
    );

    #2209366
    Ying
    Staff
    Customer Support

    Hi 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 )
    )
    );}
    #2209392
    Rupert

    Hey 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!

    #2209427
    Ying
    Staff
    Customer Support

    In 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/

    #2209453
    Rupert

    Hey 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!

    #2209502
    Ying
    Staff
    Customer Support

    author 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' )
    )
    );}
    #2209522
    Rupert

    Perfect, 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 🙂

    #2209550
    Ying
    Staff
    Customer Support

    In 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 ),
    )
    );}
    #2209570
    Rupert

    Thank you so, so much, Ying.

    It´´s very much appreciated!

    #2209576
    Ying
    Staff
    Customer Support

    You are welcome 🙂

    #2284012
    Chintan

    Hi

    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 🙂

    #2284050
    Ying
    Staff
    Customer Support

    The 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!

    #2284566
    Chintan

    Awesome 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!

    #2284652
    Ying
    Staff
    Customer Support

    Glad that you’ve got it sorted! Good job 🙂

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