Hi
I have searched and tried several possible solutions, but can’t find a way to exclude articles in specific categories from
a) showing in the big grid on category pages
b) popping up in de mega menu
I know that it is possible to configure the big grid on the homepage and that works fine. However I am not able to prevent the articles from specific categories from showing up in the big grid and showing those articles in the mega menu.
One of the solutions mentioned on the forums is https://forum.tagdiv.com/topic/how-to-hide-specific-categories/. However the code snippet mentioned there (http://screencast.com/t/3RKjibbv) is different from the most recent code in the same file. I have tried several options with
if($td_category->cat_ID != 87 and $td_category->cat_ID != 36) {
....
}
but all without succes. I did find a solution to hide the category in the category listing within the mega menu with the exclude option:
if (!empty($show_child_cat) and !empty($category_id)) {
$td_subcategories = get_categories(array(
'child_of' => $category_id,
'number' => $show_child_cat,
'exclude' => '87,36'
));
However, I have had no success in preventing the article itself showing up under ‘All’. Can you provide me with an adequate solution?
-
This topic was modified 10 years by
indebuurt.
Hi,
For posts you woudl have to modify the query and you can do it here: http://screencast.com/t/D6ynnxBEtmN and use a the below condition to detect the mega menu block class and the category to alter based on its id then set the “category_ids” attribute to filter posts based on your category id and exclude the subcategory based on its id also. Here is the code I’ve used:
if (get_class($this) == 'td_block_mega_menu' && $this->atts['category_id'] == 115) {
$this->atts['category_ids'] = "115, -144";
}
Hope this helps!
Thanks
Hi
Thanks for the quick reply. I tried your code but without any luck. I have two images to illustrate what I am trying to accomplisch.Perhaps showing it helps you better understand or give me a hint on what I am doing wrong with your code.
The site has several Categories with Subcategories. One of those Categories is ‘Nieuws’ (Dutch for News). The category id for this category is 23. Nieuws has several subcategories, such as ‘File’ (Dutch for traffic jam). The category id for this category is 87.
I tried accomplishing what I want with this code:
if (get_class($this) == 'td_block_mega_menu' && $this->atts['category_id'] == 23) {
$this->atts['category_ids'] = "23, -87";
}
However, the result is still the same. The articles from the category File keep popping up in the mega menu and on the category page in the big grid.


Hope you can assist me further.
Hi,
I tested this again myself and it works as expected. I filtered different categories and it works. The solution provided by Lucian works only for the mega-menu. If you want to alter the big grid you have to adapt the code and apply it to the grid template here: http://screencast.com/t/V63ptb4s60oP
I have also checked your website and the solution worked on your end as well (it could have been the cache)
http://screencast.com/t/eT0wLlDh
Thank you!
Hi
Thanks for the quick reply. We really appreciate it! Checking the cache did the trick for the mega menu. The reason you assumed the solution worked on my end was because I deleted the articles in the category. I have restored one and can confirm that it is not showing in the mega menu, but it is visible in the big grid on the category page. I have followed your suggestion to apply the code to the grid template. Can you help me with altering the code and applying it in the code? I have looked at the code in the correct file, but don’t know how and where.
<?php
class td_category_top_posts_style_3 extends td_category_top_posts_style {
function show_top_posts() {
parent::render_posts_to_buffer();
if (parent::get_rendered_post_count() == 0) {
return; // die here
}
?>
<!-- big grid -->
<div class="td-category-grid">
<div class="td-container">
<div class="td-pb-row">
<div class="td-pb-span12">
<?php
echo parent::get_buffer();
?>
</div>
</div>
</div>
</div>
<?php
}
}
Hi,
We provided the mega-menu example but any further customization will have to be made by yourself as we cannot offer customization services at the moment. The top post class extends the td_category_top_post_style class that can be found here: http://screencast.com/t/h9YbfMis
If you cannot adapt the code yourself you will have to hire some help from sites like studio.envato.com
Thank you for your understanding.
