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

    olivial
    Participant

    Hello,

    I have two questions about authors/users on my site.

    1. For some reason the author/post meta link is not linking to anything. It used to link to an archive page of that specific author’s past posts. How do I get this link back in the post meta?

    2. How can I customize the author archive page? I want to include a photo (user avatar photo) of the author and their name with a short bio/description of the author preferably on the top of the page. This is a pretty basic WP function, but I cannot figure out how to get it to work with X-Themes.

    Thank you for your help!
    Olivia

    #251391

    John Ezra
    Member

    Hi Olivia,

    Thanks for writing in! To assist you with this issue, would you mind providing us with your URL. This is to ensure that we can provide you with a tailored answer to your situation. Once you have provided us with your URL, we will be happy to assist you with everything. Thanks!

    #251395

    olivial
    Participant
    This reply has been marked as private.
    #251566

    Zeshan
    Member

    Hi Olivial,

    Thanks for writing in!

    Because this requires a template change, I’d advise that you setup a child theme. This allows you to make code changes that won’t be overwritten when an X update is released. After your child theme is setup, please review how we recommend making template changes in Customization Best Practices.

    #1: To add author link to your post meta, add following in your child theme’s functions.php file:

    // Entry Meta
    // =============================================================================
    
    if ( ! function_exists( 'x_ethos_entry_meta' ) ) :
      function x_ethos_entry_meta() {
    
        //
        // Author.
        //
    
        // $author = sprintf( ' %1$s %2$s</span>',
        //   __( 'by', '__x__' ),
        //   get_the_author()
        // );
    
        $author = ' by <a href="'.  get_author_posts_url(get_the_author_meta( 'ID' )) . '">' . get_the_author() . '</a></span>';
    
        //
        // Date.
        //
    
        $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() )
        );
    
        //
        // Categories.
        //
    
        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>%1$s %2$s',
              __( 'In', '__x__' ),
              trim( $categories_output, $separator )
            );
          } else {
            $categories_list = '';
          }
        } elseif ( get_post_type( get_the_ID() ) != 'post' ) {
    
          if ( has_term( '', 'video-cat', NULL ) ) {
            $categories        = get_the_terms( get_the_ID(), 'video-cat' );
            $separator         = ', ';
            $categories_output = '';
            foreach ( $categories as $category ) {
              $categories_output .= '<a href="'
                                  . get_term_link( $category->slug, 'video-cat' )
                                  . '" title="'
                                  . esc_attr( sprintf( __( "View all posts in: &ldquo;%s&rdquo;", '__x__' ), $category->name ) )
                                  . '"> '
                                  . $category->name
                                  . '</a>'
                                  . $separator;
            }
    
            $categories_list = sprintf( '<span>%1$s %2$s',
              __( 'In', '__x__' ),
              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>%1$s %2$s',
            __( 'In', '__x__' ),
            trim( $categories_output, $separator )
          );
        }
    
        //
        // Comments link.
        //
    
        if ( comments_open() ) {
    
          $title  = apply_filters( 'x_entry_meta_comments_title', get_the_title() );
          $link   = apply_filters( 'x_entry_meta_comments_link', get_comments_link() );
          $number = apply_filters( 'x_entry_meta_comments_number', get_comments_number() );
    
          if ( $number == 0 ) {
            $text = __( 'Leave a Comment' , '__x__' );
          } else if ( $number == 1 ) {
            $text = $number . ' ' . __( 'Comment' , '__x__' );
          } else {
            $text = $number . ' ' . __( 'Comments' , '__x__' );
          }
    
          $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 ) ),
            $text
          );
    
        } else {
    
          $comments = '';
    
        }
    
        //
        // Output.
        //
    
        if ( x_does_not_need_entry_meta() ) {
          return;
        } else {
          printf( '<p class="p-meta">%1$s%2$s%3$s%4$s</p>',
            $categories_list,
            $author,
            $date,
            $comments
          );
        }
    
      }
    endif;
    

    #2: To show author box above the posts on your author page, please add following in your child theme’s functions.php file:

    // Show Author Box on Author Page
    // =============================================================================
    
    function add_author_meta() {
      if ( is_author() ) {
        $id = get_the_author_meta( 'ID' );
        echo do_shortcode('[author id="'.$id.'"]');
      }
    }
    
    add_action('x_before_view_global__index', 'add_author_meta');
    

    Hope this helps. 🙂

    Thank you.

    #252166

    olivial
    Participant

    Thank you so much! That worked!

    #252224

    Nico
    Moderator

    You’re most welcome.

    Let us know if you need anything else.

    Thanks. Have a great day! 🙂

    #263126

    Syed Shadab M
    Participant

    Hello there,

    Thanks for the information provided here. Can we load a custom author template here? x_get_view?

    #263401

    Rad
    Moderator

    Hi there,

    Not possible, because it’s part of functions.php but you can create another template and add it at /x-child/framework/views/global/

    Let say you named it /x-child/framework/views/ethos/author-template.php and inside it should be this code :

    <?php x_ethos_entry_meta() ?>

    Or this code :

    <?php $id = get_the_author_meta( 'ID' ); echo do_shortcode('[author id="'.$id.'"]'); ?>

    Then you can call it as

    x_get_view('ethos', 'author-template');

    Hope this helps.

    #291994

    Joseph B
    Participant

    Hello the code that was provided does not work for me. I will provide my URL in the next private post.

    #291995

    Joseph B
    Participant
    This reply has been marked as private.
    #292283

    Paul R
    Moderator

    Hi Joseph,

    The code was meant for Ethos stack while your site is using integrity stack.

    For integrity Stack, add the code below in your child theme functions.php file

    
    // Entry Meta
    // =============================================================================
    function x_integrity_entry_meta() {
    
        //
        // Author.
        //
    
        $author = sprintf( '<span><a href="%1s"><i class="x-icon-pencil" data-x-icon=""></i> %2s</a></span>',
        get_author_posts_url(get_the_author_meta( 'ID' )),
          get_the_author()
        );
    
        //
        // Date.
        //
    
        $date = sprintf( '<span><time class="entry-date" datetime="%1$s"><i class="x-icon-calendar" data-x-icon=""></i> %2$s</time></span>',
          esc_attr( get_the_date( 'c' ) ),
          esc_html( get_the_date() )
        );
    
        //
        // Categories.
        //
    
        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 ) )
                                  . '"><i class="x-icon-bookmark" data-x-icon=""></i> '
                                  . $category->name
                                  . '</a>'
                                  . $separator;
            }
    
            $categories_list = sprintf( '<span>%s</span>',
              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 ) )
                                . '"><i class="x-icon-bookmark" data-x-icon=""></i> '
                                . $category->name
                                . '</a>'
                                . $separator;
          }
    
          $categories_list = sprintf( '<span>%s</span>',
            trim( $categories_output, $separator )
          );
        }
    
        //
        // Comments link.
        //
    
        if ( comments_open() ) {
    
          $title  = apply_filters( 'x_entry_meta_comments_title', get_the_title() );
          $link   = apply_filters( 'x_entry_meta_comments_link', get_comments_link() );
          $number = apply_filters( 'x_entry_meta_comments_number', get_comments_number() );
    
          if ( $number == 0 ) {
            $text = __( 'Leave a Comment' , '__x__' );
          } else if ( $number == 1 ) {
            $text = $number . ' ' . __( 'Comment' , '__x__' );
          } else {
            $text = $number . ' ' . __( 'Comments' , '__x__' );
          }
    
          $comments = sprintf( '<span><a href="%1$s" title="%2$s" class="meta-comments"><i class="x-icon-comments" data-x-icon=""></i> %3$s</a></span>',
            esc_url( $link ),
            esc_attr( sprintf( __( 'Leave a comment on: &ldquo;%s&rdquo;', '__x__' ), $title ) ),
            $text
          );
    
        } else {
    
          $comments = '';
    
        }
    
        //
        // Output.
        //
    
        if ( x_does_not_need_entry_meta() ) {
          return;
        } else {
          printf( '<p class="p-meta">%1$s%2$s%3$s%4$s</p>',
            $author,
            $date,
            $categories_list,
            $comments
          );
        }
    
      }
    
    // Show Author Box on Author Page
    // =============================================================================
    
    function add_author_meta() {
      if ( is_author() ) {
        $id = get_the_author_meta( 'ID' );
        echo do_shortcode('[author id="'.$id.'"]');
      }
    }
    
    add_action('x_before_view_global__index', 'add_author_meta');
    

    Hope that helps.

    #294681

    Joseph B
    Participant

    Works great! Thanks! What if I want it to work for a custom taxonomy like the byline that I have in my website?

    #295118

    Nico
    Moderator

    Hi There,

    You’re most welcome. and for you next concern, we are not certainly not sure of what do you want to achieve. Would you mind sharing us more details of what you want to achieve. Thank you so much.

    #301759

    Joseph B
    Participant

    Since on my website, I am posting articles written by other people, I added a custom taxonomy instead of the author called byline.

    If you follow the link in the next post, you’ll see there are different authors for the different articles. I want when I click on those links to show all the articles written by that author, just like how it is for the actual wordpress author.

    #301760

    Joseph B
    Participant
    This reply has been marked as private.