-
AuthorPosts
-
April 16, 2015 at 8:46 am #251286
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!
OliviaApril 16, 2015 at 11:24 am #251391Hi 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!
April 16, 2015 at 11:34 am #251395This reply has been marked as private.April 16, 2015 at 3:17 pm #251566Hi 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: “%s”", '__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: “%s”", '__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: “%s”", '__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: “%s”', '__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.
April 17, 2015 at 10:21 am #252166Thank you so much! That worked!
April 17, 2015 at 11:50 am #252224You’re most welcome.
Let us know if you need anything else.
Thanks. Have a great day! 🙂
May 1, 2015 at 9:32 am #263126Hello there,
Thanks for the information provided here. Can we load a custom author template here? x_get_view?
May 1, 2015 at 6:48 pm #263401Hi 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.
June 3, 2015 at 10:07 pm #291994Hello the code that was provided does not work for me. I will provide my URL in the next private post.
June 3, 2015 at 10:07 pm #291995This reply has been marked as private.June 4, 2015 at 3:40 am #292283Hi 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: “%s”", '__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: “%s”", '__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: “%s”', '__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.
June 6, 2015 at 10:06 pm #294681Works great! Thanks! What if I want it to work for a custom taxonomy like the byline that I have in my website?
June 7, 2015 at 12:29 pm #295118Hi 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.
June 14, 2015 at 5:33 pm #301759Since 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.
June 14, 2015 at 5:33 pm #301760This reply has been marked as private. -
AuthorPosts