How to add related post in wordpress?

How to add related post in WordPress, code for related post, php code for related post in wp, php code for related post in WordPress, show related post without plugin in WordPress, custom code for related post in WordPress. you want to add related post in your blog site or any site? related post show without any plugin in WordPress? Please see our instruction, from here you can get easily add related post in your site without any plugin. just follow our instruction.

Now open your single.php file and copy and paste below code where you see the related post.


<div class="relatedpost" style="margin-top:20px;">
<?php $brnewsthemerelated_post = $post;
global $post;
$categories = get_the_category($post->ID);
if ($categories) {
$category_ids = array();
foreach($categories as $individual_category) $category_ids[] = $individual_category->term_id;

$args=array(
'category__in' => $category_ids,
'post__not_in' => array($post->ID),
'posts_per_page'=> 3, //you can change Number of related posts that will be shown.
'caller_get_posts'=>1
);

$brnewsthemerelatedpost_query = new wp_query( $args );
if( $brnewsthemerelatedpost_query->have_posts() ) {
echo '<div id="related-posts"><h3 class="sidebar-title">Related Articles</h3><div>';
while( $brnewsthemerelatedpost_query->have_posts() ) {
$brnewsthemerelatedpost_query->the_post();?>
<?php $embaded_link= get_post_meta($post->ID, 'embaded_link', true); ?>

<div class="related-post-item grid3">
<?php if ( has_post_thumbnail() ) : ?>
<div class="post-thumbs">
<div class="img-box">
<img src="<?php the_post_thumbnail_url('thumbs'); ?>"/>
<div class="ovrly"></div>
<div class="buttons">
<a class="fa fa-search info" href="<?php the_post_thumbnail_url(); ?>" rel="prettyPhoto" title="<?php the_title_attribute(); ?>"></a>
<a class="fa fa-link info" href="<?php the_permalink(); ?>"></a>

</div>
</div>
</div>

<?php endif; ?>
<div class="entry">
<h6><span class="post-title"><a href="<?php the_permalink(); ?>"><?php the_title(); ?></a></span></h6>
<div class="meta-post">
<div class="meta-data date"><?php the_time('F j, Y') ?></div>
<div class="meta-data post-author"><?php the_author(); ?></div>

</div>
<p><?php echo the_excerpt();?></p>
</div>

</div>
<?php
}
echo '</div></div>';
}
}
$post = $brnewsthemerelated_post;
wp_reset_query(); ?>
</div>

Now you just write your own css in your css file, that what you need.

​Leave a Comment

Comment authors age:




How to add next and previous post in WordPress?

How Many SIM Registered by Your NID? জেনে নিন আপনার জাতীয় পরিচয়পত্র দিয়ে কত গুলো সিম রেজিস্টার করা আছে।