Navigation
This is archived content. Visit our new forum.
  • Author
    Posts
  • #71539

    John L
    Participant

    Hello!

    I’ve found the answer to half of my issue (how to add author’s name to post) from this thread: http://theme.co/x/member/forums/topic/author-display/

    However, is there a way to make it so that the author’s name is clickable (as a link) to that particular author’s page?

    #71859

    Paula S
    Member

    Hi John,

    Thanks for writing in. I am curious as which function you’re after as you can simply add the script as shown here:

    <?php $author = get_the_author(); ?>

    and have the post show the author’s public name. Or if you’re after the author’s name with a link to a page, you can add this code instead (Take note that the website link should be filled up through the author’s profile when then sign in)

    <p>Written by: <?php the_author_link(); ?></p>

    Hope this helps!

    #72036

    John L
    Participant

    Awesome, thanks!

    It was the 2nd script that I was looking for.

    Can you tell me where I need to add the script to? I am using a Child (Ethos) theme as well.

    #72483

    Iris C
    Member

    Hi John,

    Thanks for writing in!

    In the Edit Post page, you will find Screen Options at the top. Select the checkbox with the label Author. By selecting this, your post will display the author, category, and date of the post.

    To put a link on the author’s name, paste the following in the child theme’s functions.php file:

    if ( ! function_exists( 'x_ethos_entry_meta' ) ) :
      function x_ethos_entry_meta() {
    
        $author = ' by <a href="'.  get_bloginfo('url').'/author/'.get_the_author_link().'">'.get_the_author().'</a></span>';
    
        $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%2$s</time></span>',
          esc_attr( get_the_date( 'c' ) ),
          esc_html( get_the_date() )
        );
    
        if ( get_post_type() == 'x-portfolio' ) {
          if ( has_term( '', 'portfolio-category', NULL ) ) {
            $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
            $separator         = ', ';
            $categories_output = '';
            foreach ( $categories as $category ) {
              $categories_output .= '<a href="'
                                  . get_term_link( $category->slug, 'portfolio-category' )
                                  . '" title="'
                                  . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                  . '"> '
                                  . $category->name
                                  . '</a>'
                                  . $separator;
            }
    
            $categories_list = sprintf( '<span>In %s',
              trim( $categories_output, $separator )
            );
          } else {
            $categories_list = '';
          }
        } else {
          $categories        = get_the_category();
          $separator         = ', ';
          $categories_output = '';
          foreach ( $categories as $category ) {
            $categories_output .= '<a href="'
                                . get_category_link( $category->term_id )
                                . '" title="'
                                . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                . '"> '
                                . $category->name
                                . '</a>'
                                . $separator;
          }
    
          $categories_list = sprintf( '<span>In %s',
            trim( $categories_output, $separator )
          );
        }
    
        if ( comments_open() ) {
          $title  = get_the_title();
          $link   = get_comments_link();
          $number = get_comments_number();
          if ( $number == 0 ) {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( $link ),
              esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
              __( 'Leave a Comment' , '__x__' )
            );
          } else if ( $number == 1 ) {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( $link ),
              esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
              $number . ' ' . __( 'Comment' , '__x__' )
            );
          } else {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( $link ),
              esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
              $number . ' ' . __( 'Comments' , '__x__' )
            );
          }
        } else {
          $comments = '';
        }
    
        $post_type           = get_post_type();
        $post_type_post      = $post_type == 'post';
        $post_type_portfolio = $post_type == 'x-portfolio';
        $no_post_meta        = x_get_option( 'x_blog_enable_post_meta' ) == 0;
        $no_portfolio_meta   = x_get_option( 'x_portfolio_enable_post_meta' ) == 0;
    
        if ( $post_type_post && $no_post_meta || $post_type_portfolio && $no_portfolio_meta ) {
          return;
        } else {
          printf( '<p class="p-meta">%1$s%2$s%3$s%4$s</p>',
            $categories_list,
            $author,
            $date,
            $comments
          );
        }
    
      }
    endif;

    Hope this helps!

    #87048

    STEVE H
    Participant

    Hi, I’m trying to do the same thing (make a link to the post author), and on the index pages, instead of the author’s name, it says author”>author, and the first author is a link, but it goes to an Oops error. Any idea what I did wrong? I’m on the latest version of wordpress and X. The website is travel studies.org. You can see the problem on the home page. Thanks for your help.

    #87082

    Cousett
    Member

    Are you also using a child theme based on Ethos? Could you send us your login information so we can look into it further.

    To do this, you can make a post with the following info:

    – Link to your site
    – WordPress Admin username / password
    – FTP credentials

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    #87116

    STEVE H
    Participant
    This reply has been marked as private.
    #87340

    Paul R
    Moderator

    Hi Steve,

    Yes please send us the ftp credentials as well.

    Don’t forget to select Set as private reply. This ensures your information is only visible to our staff.

    Thanks

    #87504

    STEVE H
    Participant
    This reply has been marked as private.
    #87589

    Paul R
    Moderator

    Hi Steve,

    I could not login using the ftp credentials you gave.

    Please put this code in functions.php of your child theme.

    
    <?php
    
    // =============================================================================
    // FUNCTIONS.PHP
    // -----------------------------------------------------------------------------
    // Overwrite or add your own custom functions to X in this file.
    // =============================================================================
    if ( ! function_exists( 'x_ethos_entry_meta' ) ) :
      function x_ethos_entry_meta() {
    
        $author = sprintf( ' by <a href="'.get_the_author_link().'">%s</a></span>',
          get_the_author()
        );
        
        $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%2$s</time></span>',
          esc_attr( get_the_date( 'c' ) ),
          esc_html( get_the_date() )
        );
    
        if ( get_post_type() == 'x-portfolio' ) {
          if ( has_term( '', 'portfolio-category', NULL ) ) {
            $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
            $separator         = ', ';
            $categories_output = '';
            foreach ( $categories as $category ) {
              $categories_output .= '<a href="'
                                  . get_term_link( $category->slug, 'portfolio-category' )
                                  . '" title="'
                                  . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                  . '"> '
                                  . $category->name
                                  . '</a>'
                                  . $separator;
            }
    
            $categories_list = sprintf( '<span>In %s',
              trim( $categories_output, $separator )
            );
          } else {
            $categories_list = '';
          }
        } else {
          $categories        = get_the_category();
          $separator         = ', ';
          $categories_output = '';
          foreach ( $categories as $category ) {
            $categories_output .= '<a href="'
                                . get_category_link( $category->term_id )
                                . '" title="'
                                . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                . '"> '
                                . $category->name
                                . '</a>'
                                . $separator;
          }
    
          $categories_list = sprintf( '<span>In %s',
            trim( $categories_output, $separator )
          );
        }
    
        if ( comments_open() ) {
          $title  = get_the_title();
          $link   = get_comments_link();
          $number = get_comments_number();
          if ( $number == 0 ) {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( $link ),
              esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
              __( 'Leave a Comment' , '__x__' )
            );
          } else if ( $number == 1 ) {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( $link ),
              esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
              $number . ' ' . __( 'Comment' , '__x__' )
            );
          } else {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( $link ),
              esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
              $number . ' ' . __( 'Comments' , '__x__' )
            );
          }
        } else {
          $comments = '';
        }
    
        $post_type           = get_post_type();
        $post_type_post      = $post_type == 'post';
        $post_type_portfolio = $post_type == 'x-portfolio';
        $no_post_meta        = x_get_option( 'x_blog_enable_post_meta' ) == 0;
        $no_portfolio_meta   = x_get_option( 'x_portfolio_enable_post_meta' ) == 0;
    
        if ( $post_type_post && $no_post_meta || $post_type_portfolio && $no_portfolio_meta ) {
          return;
        } else {
          printf( '<p class="p-meta">%1$s%2$s%3$s%4$s</p>',
            $categories_list,
            $author,
            $date,
            $comments
          );
        }
    
      }
    endif;
    

    Thanks

    #87799

    STEVE H
    Participant
    This reply has been marked as private.
    #87811

    Egis B
    Participant

    All codes doesn’t work.

    if ( ! function_exists( ‘x_ethos_entry_meta’ ) ) :
    function x_ethos_entry_meta() {

    $author = ‘ by ‘.get_the_author().’</span>’;

    ————-

    if ( ! function_exists( ‘x_ethos_entry_meta’ ) ) :
    function x_ethos_entry_meta() {

    $author = sprintf( ‘ by %s</span>’,
    get_the_author()
    );
    ————-

    What is the correct code?

    #87888

    Zeshan
    Member

    Hi Egis & Steve,

    We’re sorry for the confusion. Instead of using the above provided code, please try adding the following code in your child theme’s functions.php file:

    if ( ! function_exists( 'x_ethos_entry_meta' ) ) :
      function x_ethos_entry_meta() {
    
          $author = ' by <a href="'.  get_author_posts_url(get_the_author_meta( 'ID' )) . '">' . get_the_author() . '</a></span>';
    
        $date = sprintf( '<span><time class="entry-date" datetime="%1$s">%2$s</time></span>',
          esc_attr( get_the_date( 'c' ) ),
          esc_html( get_the_date() )
        );
    
        if ( get_post_type() == 'x-portfolio' ) {
          if ( has_term( '', 'portfolio-category', NULL ) ) {
            $categories        = get_the_terms( get_the_ID(), 'portfolio-category' );
            $separator         = ', ';
            $categories_output = '';
            foreach ( $categories as $category ) {
              $categories_output .= '<a href="'
                                  . get_term_link( $category->slug, 'portfolio-category' )
                                  . '" title="'
                                  . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                  . '"> '
                                  . $category->name
                                  . '</a>'
                                  . $separator;
            }
    
            $categories_list = sprintf( '<span>In %s',
              trim( $categories_output, $separator )
            );
          } else {
            $categories_list = '';
          }
        } else {
          $categories        = get_the_category();
          $separator         = ', ';
          $categories_output = '';
          foreach ( $categories as $category ) {
            $categories_output .= '<a href="'
                                . get_category_link( $category->term_id )
                                . '" title="'
                                . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                . '"> '
                                . $category->name
                                . '</a>'
                                . $separator;
          }
    
          $categories_list = sprintf( '<span>In %s',
            trim( $categories_output, $separator )
          );
        }
    
        if ( comments_open() ) {
          $title  = get_the_title();
          $link   = get_comments_link();
          $number = get_comments_number();
          if ( $number == 0 ) {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( $link ),
              esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
              __( 'Leave a Comment' , '__x__' )
            );
          } else if ( $number == 1 ) {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( $link ),
              esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
              $number . ' ' . __( 'Comment' , '__x__' )
            );
          } else {
            $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments">%3$s</a></span>',
              esc_url( $link ),
              esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
              $number . ' ' . __( 'Comments' , '__x__' )
            );
          }
        } else {
          $comments = '';
        }
    
        $post_type           = get_post_type();
        $post_type_post      = $post_type == 'post';
        $post_type_portfolio = $post_type == 'x-portfolio';
        $no_post_meta        = x_get_option( 'x_blog_enable_post_meta' ) == 0;
        $no_portfolio_meta   = x_get_option( 'x_portfolio_enable_post_meta' ) == 0;
    
        if ( $post_type_post && $no_post_meta || $post_type_portfolio && $no_portfolio_meta ) {
          return;
        } else {
          printf( '<p class="p-meta">%1$s%2$s%3$s%4$s</p>',
            $categories_list,
            $author,
            $date,
            $comments
          );
        }
    
      }
    endif;
    

    Hope this helps. 🙂

    Thank you.

    #87913

    STEVE H
    Participant

    Wow, that worked like a charm! Thanks very much! Now all it needs is something at the top of the page saying something like “Author’s Blog” in h3 or h4. Do you know if that been addressed on the forum?

    Thank you very much for this. Your support team is amazing.

    #87934

    Egis B
    Participant

    Thank You very much!

    Works great!

    It may be possible add edit post link after Leave a Comment?