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

    anilanvesh
    Participant

    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?

    #75319

    Christian
    Moderator

    Hey 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. 🙂

    #75326

    anilanvesh
    Participant

    It works, thanks 🙂

    #75774

    Christian
    Moderator

    You’re welcome Anilanvesh.

    #144000

    Joshua M
    Participant

    Will this need to be updated every time the Theme is updated? I’m not using a child theme is all.

    #144281

    Rubin
    Keymaster

    Hey 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/

    #220554

    Brian J
    Participant

    You 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;
    }
    #220849

    Darshana
    Moderator

    Thank you Brian J, for your contribution 🙂

    #220887

    Brian J
    Participant

    No problem. I added an update to the code as I found a conflict with a recent posts plugin that used the content filters.

    #221167

    Nico
    Moderator

    Thanks 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!

    #246068

    Julia T
    Participant

    Brian,

    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…

    #246136

    Rue Nel
    Moderator

    Hello 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.

    #246303

    Julia T
    Participant
    This reply has been marked as private.
    #246507

    Zeshan
    Member

    Hi 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!

    #247023

    Julia T
    Participant

    You are right ‘SEO by Yoast’ causes that. SEO – Titles and Meta – Archives – (unselect) Disable the author archives. Now everything is working. Thank you