In this post, I am going to explain how to Display Related Posts on post single page in WordPress. In WordPress you can display related posts using plugin because lots of plugin available of WordPress. But in this post we can show you how to display related posts without any plugin.
There are two methods of display related post on single post page and you can choose whichever method you prefer. One way is doing it with a plugin and then there is another method that is doing it without any plugin.
Display Related Posts in WordPress without any Plugin
Please copy the below code and paste the following code in single.php where you want to display related post.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
<?php //This code use in the loop, list 5 post titles related to first tag on current post $tags = wp_get_post_tags($post->ID); if ($tags) { echo '<h1>Related Posts</h1>'; $first_tag = $tags[0]->term_id; $args=array( 'tag__in' => array($first_tag), 'post__not_in' => array($post->ID), 'posts_per_page'=>5, 'caller_get_posts'=>1 ); $my_query = new WP_Query($args); if( $my_query->have_posts() ) { while ($my_query->have_posts()) : $my_query->the_post(); ?> <a href="<?php the_permalink() ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a> <?php endwhile; } wp_reset_query(); } ?> |
I have used WP_query function for display related posts on single page of post.
We hope that this article is helpful for WordPress beginners. You may also want to see our other posts of WordPress then click https://webprepration.com/category/wordpress/ and also you can follow on social sites etc.
Thanks!!!
I’m a full-stack developer. My hobby and profession to write blog and programming tips that helps to others. I am a great admirer of PHP, Laravel, Codeigniter, AngularJS, Vue.js, Javascript, JQuery, WordPress, Plugin Development, Theme Development and Bootstrap from the early stage.
Great beat ! I would like to apprentice whilst you amend your website, how can i subscribe for a weblog web site? The account aided me a appropriate deal. I have been a little bit familiar of this your broadcast offered vibrant clear concept
I love it when people come together and share opinions, great blog, keep it up.
I?¦ve learn some excellent stuff here. Certainly worth bookmarking for revisiting. I surprise how much effort you put to create any such fantastic informative site.
Thanks
I simply want to say I am just all new to blogging and site-building and certainly liked your blog. Almost certainly I’m going to bookmark your blog . You surely have great articles and reviews. Cheers for revealing your website.
I hope you all are having a great weekend. I added a new list. This one is smaller, but still useful. I think the next one will be bigger.
Thank you for your blog article.Really looking forward to read more. Will read on…
I cannot thank you enough for the blog post.Really looking forward to read more. Awesome.
I cannot thank you enough for the blog post.Really looking forward to read more. Awesome.
Pretty! This was a really wonderful post. Thank you for your provided information.
I appreciate you sharing this blog article. Much obliged.
Say, you got a nice blog post.Thanks Again.
I cannot thank you enough for the post.Really looking forward to read more. Cool.
I like what you guys are usually up too. This sort of clever work and reporting! Keep up the terrific works guys I’ve included you guys to my blogroll.
A big thank you for your blog article.Thanks Again. Want more.
Pretty part of content. I simply stumbled upon your website and in accession capital to say that
I acquire actually loved account your blog posts.
Any way I’ll be subscribing in your feeds and even I achievement you get right of entry
to consistently rapidly.
It is appropriate time to make some plans for the future and it’s time to be happy. I’ve read this post and if I could I desire to suggest you few interesting things or advice. Maybe you can write next articles referring to this article. I want to read more things about it
Regards
I appreciate you sharing this blog article. Much obliged.
Say, you got a nice blog post.Thanks Again.
Wow, amazing blog format! How long have you been blogging for? you make blogging glance easy. The entire glance of your website is great, let alone the content material!
You need to be a part of a contest for one of the greatest sites on the internet. I’m going to recommend this blog!
Way cool! Some extremely valid points! I appreciate you writing this write-up and the rest of the site is also really good.|
Pretty! This has been an extremely wonderful article. Many thanks for providing this information.
Hello! I could have sworn I’ve been to this site before but after going through a few of the posts I realized it’s new to me. Anyways, I’m certainly pleased I stumbled upon it and I’ll be bookmarking it and checking back frequently!
Hey There. I discovered your blog the use of msn. That is an extremely neatly written article. I’ll make sure to bookmark it and return to learn extra of your helpful info. Thank you for the post. I’ll definitely return.
Spot on with this write-up, I absolutely think this website needs a great deal more attention. I’ll probably be back again to read more, thanks for the info!