12% off of LTD using this coupon: TWELVEPERCENTOFF. Promo ends on 2 Dec midnight UTC.
Published on Dec 2, 2020

Other Posts in the same category while excluding the current post in Oxygen

Sridhar Katakam

This members-only tutorial provides the steps to use pre_get_posts in a Code Block above a Repeater or Easy Posts component to limit posts to only those in the same category as the current post while excluding the current post being viewed.

We shall set up the above in an Oxygen Template that applies to singular posts to show a x number of related posts in a "sidebar".

Screenshot of "Vero aut inventore" category in WP admin

Step 1

Create/edit the Oxygen Template that applies to all singular posts.

Add a Section having a Columns component with 60 40 arrangement.

[optional] Select the left Column Div and change the width to 70%. That will automatically change the right Div's width to 30%.

In the left Div show post's content by either adding an Inner Content component or + Add > WordPress > Dynamic Data > Content.

In the right Div add a h3/h4 Heading reading say, "Related Posts".

Add an Easy Posts component (or a Repeater if you wish, in this example we shall use EP).

Set the WP Query to this manual query:


This will show 5 most recent posts across all the categories including the current post (if it's in the latest 5).

In my test site I changed the Template PHP and CSS to simply show linked post titles.

Template PHP:

<div class='oxy-post'>
	<a class='oxy-post-title' href='<?php the_permalink(); ?>'><?php the_title(); ?></a>


Template CSS:

%%EPID%% .oxy-post {
  margin-bottom: 1em;

%%EPID%% .oxy-post-title {
  line-height: 1.2em;

Now let's filter these out to only the posts that belong the same category/categories as the current one AND exclude the current post.

Step 2

Add a Code Block ABOVE the Easy Posts component.


This is a premium members-only content.

To view the rest of the content, please sign up for membership ($47/month or $599 one-time).

Already a member? Log in below or here.