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

Recent Posts

The Sharp-Looking Guy: 5 Essential Tips for Men to Become Sharp

We've gotten so used to seeing men streetwear joggers, ripped jeans, and sleeveless shirts. Hair…

1 day ago

How to Use Your Wedding Jewellery In Unique Ways At Festivals

When it comes to festivals, the options for wedding jewellery are endless. You can go…

1 day ago

5 Tips On Window Cleaning

Whether it concerns your home or an office building, the state of a property’s windows…

2 days ago

Sustainable Business Practices: A Win-Win Strategy

You know that running an environmentally sustainable business is the right thing to do. But…

2 days ago

Unlock Growth – Guide to Online Financing and Business Loans for Entrepreneurs

If you are in a financial crisis , or need to start a new business…

2 days ago

7 Key Factors That Help In Selecting the Best Fleet Management Software

To realize the strategic advantage from the fleet management system (FMS) and differentiate the business…

2 days ago