How to add authors bio related posts etc below the post


Hi Anupam,

There is no shortcode in Beans for the Autor box and Related posts so as you correctly stated, you have add it yourself or perhaps use a plugin.

In is in the road map to add a serie of plugins for Beans to add that kind of functionalities but I don't have an ETA on that.

Cheers,


Hey Thierry,

Thanks for the information. And i wanted to know how to show the popular posts in the theme..??


Hey Anupam, same regarding popular posts, it would probably be part of the related posts plugin πŸ™‚


Hello Anupam,

As far as related posts are concerned, you could try something like this.

add_action( 'beans_footer_before_markup', 'related_posts_categories', 5 );

function related_posts_categories() {

  if ( is_singular( 'post' ) ) {
   global $post;

   $count = 0;
   $postIDs = array( $post->ID );
    $related = '';
    $cats = wp_get_post_categories( $post->ID );
    $catIDs = array();

    foreach ( $cats as $cat ) {
     $catIDs[] = $cat;
   }

   $args = array(
      'category__in'          => $catIDs,
     'post__not_in'          => $postIDs,
      'showposts'             => 4,
     //'ignore_sticky_posts'   => 1,
     'orderby'               => 'rand',
      'tax_query'             => array(
       array(
          'taxonomy'  => 'post_format',
         'field'     => 'slug',
          'terms'     => array(
           'post-format-link',
           'post-format-status',
           'post-format-aside',
            'post-format-quote'
         ),
          'operator' => 'NOT IN'
        )
     )
   );

    $cat_query = new WP_Query( $args );

   if ( $cat_query->have_posts() ) {
     while ( $cat_query->have_posts() ) {
        $cat_query->the_post();
       $img = get_the_post_thumbnail( $post->ID, 'medium' );

       $related .= '<li><a href="' . get_permalink() . '" rel="bookmark" title="Permanent Link to' . get_the_title() . '">' . $img . '</a><h3><a href="' . get_permalink() . '" rel="bookmark" title="Permanent Link to' . get_the_title() . '">'. get_the_title() .'</a></h3></li>';
      }
   }

   if ( $related ) {
     printf( '<hr><div class="related-posts uk-block"><div class="uk-container uk-container-center"><h4 class="uk-h2 uk-text-center">Lire aussi</h4><p class="uk-text-large uk-text-center uk-margin-large-bottom">Related posts</p><ul class="uk-grid uk-grid-width-1-4">%s</ul></div></div>', $related );
    }

   wp_reset_query();

 }

}

This code snippet adds four related posts based on the category of the current post with a thumbnail (with NO fallback if there's no post thumbnail, be careful). In this snippet, the related posts are displayed just above the footer with beans_footer_before_markup but you can obviously put it where you want.

Hope it helps.

Mat


Hey thierry and Mathieu

thanks for the info. But actually i wanted to show them without writing all of the code πŸ˜€ so i guess i'll use the plugin.

Thank you for your suggestions.

And Mathieu that code works like a charm i show the related posts based on tags. Thank you for the help.

Write a reply

Login or register to write a reply, it's free!