DO YOU NEED A CONTENT WRITER FOR YOUR BUSINESS?

Your One-Stop Solution for All Content Needs! Click here for more!
WordPress

Show related posts in WordPress without any plugin

Share

You can show related posts in WordPress without any plugin and this will reduce your loading fast.

Using a simple code you can get related posts in WordPress. Simply write the below code and put this code anywhere you want to show on your website.

Example of related posts:

<?php
$tags = wp_get_post_tags($post->ID);
if ($tags) {
$tagIds = array();
foreach($tags as $tag) { $tagIds[] = $tag->term_id; }

$args=array(
'tag__in' => $tagIds,
'post__not_in' => array($post->ID),
'showposts'=>5,
'caller_get_posts'=>1
);

$query = new wp_query($args);
if( $query->have_posts() ) {
echo 'Related Posts';
echo '<br />';
while ($query->have_posts()) {
$query->the_post();
?>
<a href="<?php the_permalink() ?>"><?php the_title(); ?></a>
<?php
echo '<br />';
}
}
}
?>

Hence, using related tag you can get the related posts.

Read Also: Make a simple plugin – WordPress

Namaste UI

For any types of queries, you can contact us on info[at]namasteui.com.

Recent Posts

What to Do After a Car Accident

Being involved in a car accident, whether it’s a minor or major collision can be…

2 days ago

Tips To Choose the Best Truck Accident Lawyer

Have you or your loved one been involved in a truck accident? Dealing with a…

3 days ago

Family Law | What to Consider Before Getting the Divorce

Divorce is a serious decision that many families, unfortunately, face on a daily basis. It…

4 days ago

Top 100 Blog Commenting Sites List to Boost Engagement and SEO

For anyone trying to grow an online presence, interaction is just as important as publishing…

6 days ago

Guided Help That Trains You for University and Beyond

In today's competitive academic world, students are constantly juggling multiple responsibilities, from preparing for exams…

1 week ago

A Peek into the Secrets of Health

It is health that is real wealth and not pieces of gold and silver.”— Mahatma…

1 week ago