-
AuthorPosts
-
July 29, 2014 at 6:38 am #74795
Usually at the end of every blog post there should be author information, which is missing in X theme. How can I get an author box below every blog post?
July 30, 2014 at 4:34 am #75319Hey Anilanvesh,
We don’t have the author bio out of the box with X. Please modify _content-the-content.php located at wp-content\themes\x\framework\views\global. Add the line
<?php if ( is_singular( 'post' ) ) { echo do_shortcode('[author id="'.get_the_author_meta( 'ID' ).'" title="About the Author"]'); } ?>
below
<?php the_content(); ?>
or, simply replace the whole code of the file with the one below
<?php // ============================================================================= // VIEWS/GLOBAL/_CONTENT-THE-CONTENT.PHP // ----------------------------------------------------------------------------- // Display of the_content() for various entries. // ============================================================================= ?> <div class="entry-content content"> <?php the_content(); ?> <?php if ( is_singular( 'post' ) ) { echo do_shortcode('[author id="'.get_the_author_meta( 'ID' ).'" title="About the Author"]'); } ?> <?php x_link_pages(); ?> </div>
Notice the line
<?php if ( is_singular( 'post' ) ) { echo do_shortcode('[author id="'.get_the_author_meta( 'ID' ).'" title="About the Author"]'); } ?>
. That bit of code displays the author bio in single post page.If you’re using a child theme, copy the modified file in the same directory in your child theme’s folder.
Hope that helps. 🙂
July 30, 2014 at 5:10 am #75326It works, thanks 🙂
July 30, 2014 at 10:07 pm #75774You’re welcome Anilanvesh.
November 12, 2014 at 11:40 pm #144000Will this need to be updated every time the Theme is updated? I’m not using a child theme is all.
November 13, 2014 at 8:25 am #144281Hey There,
If you are not using a child theme yes. So we recommend setting up a child theme it’s really easy and quick.
You can find out more about that here: https://theme.co/x/member/kb/how-to-setup-child-themes/
March 4, 2015 at 7:57 pm #220554You don’t need to change the template file in your child theme. Filter the content using WordPress’s add_filter function. Add the following to your child theme functions.php file:
/* Add Author Box After Single Post */ add_filter( 'the_content', 'syn_x_add_author_post', 20 ); function syn_x_add_author_post( $content ) { if ( is_singular( 'post' ) ) { // Add image to the beginning of each page $content .= do_shortcode('[author id="'.get_the_author_meta( 'ID' ).'" title="About the Author"]'); }; // Returns the content. return $content; }
UPDATE 3/5/2015
To prevent the author box from showing up in the sidebar appending widget content that uses the WordPress content filter, I added conditions to ensure that the filter triggers just for the post.
/* Add Author Box After Single Post that is in the loop and in the main query */ add_filter( 'the_content', 'syn_x_add_author_post', 20 ); function syn_x_add_author_post( $content ) { if ( is_singular( 'post' ) && in_the_loop() && is_main_query() ) { // Add image to the beginning of each page $content .= do_shortcode('[author id="'.get_the_author_meta( 'ID' ).'" title="About the Author"]'); }; // Returns the content. return $content; }
March 5, 2015 at 6:20 am #220849March 5, 2015 at 7:34 am #220887No problem. I added an update to the code as I found a conflict with a recent posts plugin that used the content filters.
March 5, 2015 at 2:07 pm #221167Thanks Brian J. It would be a great guide for everyone who needs some small changes to their site and with to people who has problem with plugin conflicts.
Thank you very much!
Cheers!
April 10, 2015 at 12:49 am #246068Brian,
Thank you for providing your code. Kindly let me know how can I have a link to all the articles written by each author. Something like ‘Read more articles by …’.
Thank you in advance.
P.S. I am wondering how can I receive an email notification when someone replies to me. Currently I have to check it manually…
April 10, 2015 at 3:32 am #246136Hello There,
Thanks for updating this thread!
Regretfully, the link to all the articles written by each author is not available in the shortcode. It is only possible if you customized the author shortcode. Please try to insert this customized code in your child theme’s functions.php
// Custom Post Author shortcode // ============================================================================= add_action('init', 'change_post_author_shortcode'); function change_post_author_shortcode() { remove_shortcode( 'author' ); add_shortcode( 'author', 'x_shortcode_post_author_custom' ); } function x_shortcode_post_author_custom( $atts ) { extract( shortcode_atts( array( 'id' => '', 'class' => '', 'style' => '', 'title' => '', 'author_id' => '' ), $atts, 'author' ) ); $id = ( $id != '' ) ? 'id="' . esc_attr( $id ) . '"' : ''; $class = ( $class != '' ) ? 'x-author-box cf ' . esc_attr( $class ) : 'x-author-box cf'; $style = ( $style != '' ) ? 'style="' . $style . '"' : ''; $title = ( $title != '' ) ? $title : __( 'About the Author', '__x__' ); $author_id = ( $author_id != '' ) ? $author_id : get_the_author_meta( 'ID' ); $description = get_the_author_meta( 'description', $author_id ); $display_name = get_the_author_meta( 'display_name', $author_id ); $facebook = get_the_author_meta( 'facebook', $author_id ); $twitter = get_the_author_meta( 'twitter', $author_id ); $googleplus = get_the_author_meta( 'googleplus', $author_id ); $author_posts = get_author_posts_url( get_the_author_meta( 'ID' ) ); $facebook_output = ( $facebook ) ? "<a href=\"{$facebook}\" class=\"x-author-social\" title=\"Visit the Facebook Profile for {$display_name}\" target=\"_blank\"><i class=\"x-icon-facebook-square\"></i> Facebook</a>" : ''; $twitter_output = ( $twitter ) ? "<a href=\"{$twitter}\" class=\"x-author-social\" title=\"Visit the Twitter Profile for {$display_name}\" target=\"_blank\"><i class=\"x-icon-twitter-square\"></i> Twitter</a>" : ''; $googleplus_output = ( $googleplus ) ? "<a href=\"{$googleplus}\" class=\"x-author-social\" title=\"Visit the Google+ Profile for {$display_name}\" target=\"_blank\"><i class=\"x-icon-google-plus-square\"></i> Google+</a>" : ''; $output = "<div {$id} class=\"{$class}\" {$style}>" . "<h6 class=\"h-about-the-author\">{$title}</h6>" . get_avatar( $author_id, 180 ) . '<div class="x-author-info">' . "<h4 class=\"h-author mtn\">{$display_name}</h4>" . $facebook_output . $twitter_output . $googleplus_output . "<p class=\"p-author mbn\">{$description}</p>" . "<p class=\"p-author-links mbn\">Read more articles by <a href=\"{$author_posts}\">{$display_name}</a></p>" . '</div>' . '</div>'; return $output; } // =============================================================================
Please let us know if this works out for you.
April 10, 2015 at 9:22 am #246303This reply has been marked as private.April 10, 2015 at 2:56 pm #246507Hi Julia,
Thanks for writing in!
Upon checking, the link is pointing to the correct page (see: http://prntscr.com/6s5h09) but it’s redirecting to the homepage. In this case, you could try testing for a plugin conflict. You can do this by deactivating all third party plugins, and seeing if the problem remains. If it’s fixed, you’ll know a plugin caused the problem, and you can narrow down which one by reactivating them one at a time.
Thanks!
April 11, 2015 at 10:34 am #247023You are right ‘SEO by Yoast’ causes that. SEO – Titles and Meta – Archives – (unselect) Disable the author archives. Now everything is working. Thank you
-
AuthorPosts