How to add WordPress related posts without plugin 2022

Related posts are often used in individual blog posts, so many WordPress themes have this feature built-in by default, like Thype . In most cases you don’t need to use a plugin.

Add WordPress Related Posts feature without plugin

If you want to create a personalized related blog post element, you can use this function with a specific WPQuery:

/**
 * Get related posts of post
 * @since 1.0.0
 */
function codeless_get_related_posts( $post_id, $related_count, $args = array() ) {
  $terms = get_the_terms( $post_id, 'category' );
  
  if ( empty( $terms ) ) $terms = array();
  
  $term_list = wp_list_pluck( $terms, 'slug' );
  
  $related_args = array(
    'post_type' => 'post',
    'posts_per_page' => $related_count,
    'post_status' => 'publish',
    'post__not_in' => array( $post_id ),
    'orderby' => 'rand',
    'tax_query' => array(
      array(
        'taxonomy' => 'category',
        'field' => 'slug',
        'terms' => $term_list
      )
    )
  );

  return new WP_Query( $related_args );
}

So the posts that are displayed (as you can see from the taxonomy) are from the same category.

Below is the code sample how to use the above function to render the posts.

<?php
/**
 * Blog Template Part for displaying single blog related posts
 *
 * @package Thype
 * @subpackage Blog Parts
 * @since 1.0.0
 *
 */


$the_query = codeless_get_related_posts( get_the_ID(), 4 );
global $cl_from_element;
$cl_from_element['is_related'] = true;						
// Display posts
if ( $the_query->have_posts() ) : 

?>
<div class="cl-entry-single-section cl-entry-single-section--related">
  <h6 class="cl-entry-single-section__title cl-custom-font"><?php echo esc_attr__( 'Related Posts', 'thype' ) ?></h6>
  <div class="cl-blog cl-blog--style-simple-no_content cl-blog--module-carousel">
    <div class="cl-blog__list cl-items-container cl-carousel owl-carousel owl-theme" data-dots="1" data-nav="0" data-items="2" data-responsive="{"0": {"items":1}, "992": { "items":2 } }">
      <?php $i = 0;
        while ( $the_query->have_posts() ) : $the_query->the_post();
        

        if( has_post_thumbnail() ){
          get_template_part( 'template-parts/blog/style-simple-no_content' );
          $i++;
        }
          
        if( $i == 2 )
          break;

        endwhile;
      ?>
    </div>
  </div>
</div>

<?php endif; 

wp_reset_query();
$cl_from_element['is_related'] = false;
?>

Now let’s review a WordPress theme that has this functionality natively

WordPress themes with related posts

type | Multi-concept WordPress theme for blogs and magazines

How to add WordPress related posts without plugin 2022

Thype is incredibly versatile and surprisingly dynamic, aesthetically stunning, insanely versatile and also remarkably intuitive and also very easy to use and reliable too. The theme is customer-friendly both as a WordPress magazine and a blog theme.

Fast loading one-stop-store service for a variety of different website types, tightly packed with a variety of hassle-free and powerful tools and plugins that allow webmasters with no coding history to easily and quickly create amazing, knowledgeable and landed websites of all kinds.

If you want to see what Thype is all about, check out one of the 20 spectacular multi-concept demos or the online sneak peek feature. It has considerable scalability and works well with sites with reduced and moderate traffic.

StuffPost – Professional WordPress Theme for News & Magazines

1668854679 181 How to add WordPress related posts without plugin 2022

StuffPost is very neat and also comes with a full-size homepage slider that makes the theme look extremely professional. The homepage can be displayed as a highlighted category magazine grid.

The theme comes with mobile responsive layout as well, which makes it much easier for mobile people to buy items from your website.

These types of themes can typically be used for a variety of different purposes such as: B. to create service websites, blogs, landing pages and so on.

For example, on a single portfolio webpage, you have the choice to display the portfolio photos as a slider, slider, 2D slider, burst, full-width image, right image, left image. The actual blog and the blog pages of the design template are placed on a semi-transparent background, just like the menu on the start page. It is a fantastic and modern service for a recently built apartment or complex condominium, place of work or rental.

slide | The WordPress website builder

1668854679 432 How to add WordPress related posts without plugin 2022

Folie is a trendy, responsive, multipurpose theme that’s flexible enough to work well for almost any type of website. It has a drag-and-drop page builder that allows you to arrange themed modules and also design an interesting homepage. You can use foil to develop a one-page or multi-page website. There is a really working and extensive WordPress shop theme built for use with the WooCommerce plugin.

You have many ways to display your post, all you can do is switch between blog designs:

  • parallax
  • Home full screen
  • network
  • masonry
  • Lone Slider
  • Individual images.

AMP support for WordPress bargain features and also the most important manuscripts that can give you additional benefits in search engine optimization and make your mobile websites lightning fast. Light and clean menu bars are provided along with an Ajax portfolio attribute.

Designed to be a smart and powerful solution to the needs of modern website structure, Slide is a qualified and also proficient website design template.

The theme can be easily and easily customized to a variety of different uses due to its clean and flawless designs.

Demos are extremely customizable with very little effort, allowing you to have finished and professional-looking pages in minutes.

Amos – Creative WordPress theme for agencies and freelancers

1668854679 588 How to add WordPress related posts without plugin 2022

Amos is great for portfolios, photographers, designers, freelancers, architects, online shops or anyone else who wants to showcase their work in a creative and beautiful way. It is equipped with many important features. Amos looks perfect on any device including Google AMP for single posts.

You can set up your online store using Amos’ pre-made WooCommerce template. Amos includes 50+ content blocks to provide all the things you need to create a unique website in minutes without having any coding skills.

It also includes free and premium plugins and is compatible like: Visual Composer, Yellow Pencil, Revolution Slider, Layer Slider, Visual Composer, WPML, etc.

TheGem – Creative Multipurpose High Performance WordPress Theme

1668854680 535 How to add WordPress related posts without plugin 2022

TheGem is a versatile, responsive, high-performance WordPress theme with a modern creative design, suitable for a variety of creative website building applications. Designed and developed as the ultimate web building toolbox with design elements, styles and features.

TheGem helps you create a stunning, powerful website in minutes without touching a line of code. It features 40+ unique multipurpose theme concepts, 150 stunning demo pages, 8 navigation settings in 20+ styles, and flexible page layouts.

This theme covers the needs of freelancers, photographers, architects, businesses of any size and purpose, creative agencies, etc. It supports both multi-page and one-page website approaches.

Specular – Responsive multipurpose business theme

1668854680 454 How to add WordPress related posts without plugin 2022

In Specular, you won’t just find home variations or demos, but fully-built websites to publish online. There are 20+ ready-to-use websites built with research and dedication.

Specular offers unlimited layout customization. With easy-to-use theme options, you can create a unique and perfect page for any purpose.

You can create more than 200+ layouts and unique styles like no other theme has ever created.

It’s fully responsive whether you’re on a tablet, mobile or desktop, it looks amazing anywhere.

It is WooCommerce compatible so you can create your online store and sell your products. The theme is compatible with WooCommerce plugin

Specular is optimized for high-resolution displays. All icons are font icons and are used according to the latest CSS guidelines.

Scroll to Top