-
AuthorPosts
-
July 21, 2014 at 11:14 am #71539
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?
July 22, 2014 at 3:19 am #71859Hi 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!
July 22, 2014 at 12:03 pm #72036Awesome, 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.
July 23, 2014 at 11:32 am #72483Hi 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: “%s”", '__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: “%s”", '__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: “%s”', '__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: “%s”', '__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: “%s”', '__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!
August 18, 2014 at 2:23 pm #87048Hi, 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.
August 18, 2014 at 3:00 pm #87082Are 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 credentialsDon’t forget to select Set as private reply. This ensures your information is only visible to our staff.
August 18, 2014 at 3:59 pm #87116This reply has been marked as private.August 19, 2014 at 12:43 am #87340Hi 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
August 19, 2014 at 6:54 am #87504This reply has been marked as private.August 19, 2014 at 8:38 am #87589Hi 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: “%s”", '__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: “%s”", '__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: “%s”', '__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: “%s”', '__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: “%s”', '__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
August 19, 2014 at 12:36 pm #87799This reply has been marked as private.August 19, 2014 at 1:02 pm #87811All 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?
August 19, 2014 at 2:47 pm #87888Hi 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: “%s”", '__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: “%s”", '__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: “%s”', '__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: “%s”', '__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: “%s”', '__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.
August 19, 2014 at 3:12 pm #87913Wow, 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.
August 19, 2014 at 3:35 pm #87934Thank You very much!
Works great!
It may be possible add edit post link after Leave a Comment?
-
AuthorPosts