X Theme - Ethos - How to exclude blog category from main blog feed

Hi,

I am using the X theme (Ethos) on my website and have the following question/issue which I hope can be resolved:

Is there a way to exclude blog posts from a pre-defined category to be posted in the main feed of the main page of the website?

In my particular case, I have a main page and some additional blog pages, such as a page with press releases. I would like to avoid that these press releases (that constitute a particular blog category ‘Press Release’) that I publish on the Press Release page also appear in the main blog feed on the main page of the website.

Right now it seems that any blog post, regardless of category, is automatically published in the main feed of the main page of the website and I don’t see how I can modify this. Does someone know the answer to this?

Many thanks.

Best regards,

Maxime

Hi Maxime,

Thanks for writing in!
Excluding any category, needs custom PHP code. If you have activated child theme please add this code to your child theme function file.

function x_exclude_cat_from_blog($query) {
if ($query->is_home() && $query->is_main_query()) {
$query->set('cat', '-25');
}
}
add_action('pre_get_posts', 'x_exclude_cat_from_blog'); 

In place of 25 please add your category ID. You can find the ID in Dashboard -> Posts-> Category.

If you haven’t activated child theme please active it first and add the code for future update issues.

Thanks

Hi,

Thank you for your response.

I have a follow up question: If I want to add a second blog category to be excluded, what do I need to add in addition in the provided code? (let’s us as example a category ID called ‘26’).

Many thanks.

Best regards,

Maxime

Hello Maxime,

You may add more categories by separating them with a comma like this:

function x_exclude_cat_from_blog($query) {
    if ($query->is_home() && $query->is_main_query()) {
        $query->set('cat', '-25, -1');
    }
}
add_action('pre_get_posts', 'x_exclude_cat_from_blog');

Hope this helps.

Great. Works like a charm. Many thanks Jade.

I had one last remaining question, which I hope you could help me figure out:

In my X-theme (Ethos), I have one main sidebar that shows throughout the website.

I am looking to display one particular blog category (in my case: ‘Press Releases’) somewhere in the side bar (through a post slider display).

I was browsing through the available options in my Wordpress dashboard (Appearances>Widgets>Main Sidebar), but couldn’t find the option to plug in a particular blog category in the side bar.

Am I missing something or would you know the appropriate way to achieve this?

Many thanks.

Best regards,

Maxime

Hello Maxime,

Thanks for updating the thread.

You can take a look at following tutorial to display latest post from specific category in sidebar:

If you would like to display as a slider then you can use Soliloquy slider which can be installed from X > Validation > Extensions:

Thanks.

Hi Prasant,

Many thanks for your response. This was exactly what I was looking for.

Have installed the plug-in and it works almost perfectly.

Have one remaining issue: I have included a specific blog category ‘Press Releases’ in the side bar through the ‘Recent Posts Widget Extended’ plug in.

The blog category shows in the side bar, like I wanted, on all pages of the website except for the main blog page of the website. On the main page, the widget is not showing. My intention is to show the widget with blog category ‘Press Releases’ also on the main page blog page of the website.

I am not sure why this is the case… Could you help me figure this out?

In this regard I would like to point out that I have added code to the functions.php file (in X child theme) which excludes the blog category ‘Press Releases’ from the main blog feed on the main page (see previous posts in this topic). Perhaps this code is preventing the widget from showing the category ‘Press Releases’ on the main page? or maybe I am just missing something else?

Many thanks.

Best regards,

Maxime

Hi Maxime,

Please note that Recent Posts Widget Extended is a third party plugin.

Regretfully, we cannot provide support for third party plugins or scripts as our support policy in the sidebar states due to the fact that there is simply no way to account for all of the potential variables at play when using another developer’s plugin or script. Because of this, any questions you have regarding setup, integration, or troubleshooting any piece of functionality that is not native to X will need to be directed to the original developer.

You can try removing the code you have added in your functions.php file to check if that is the one causing the issue.

Thank you for your understanding.

This topic was automatically closed 10 days after the last reply. New replies are no longer allowed.