Quantcast
Channel: Joomla! Forum - community, help and support
Viewing all articles
Browse latest Browse all 1941

General Questions/New to Joomla! 5.x • Re: How to prevent Category List from showing articles of subcategories

$
0
0
After many trial-and-error I finally got it! The file that needs modifying is:

(JOOMLA ROOT)/layouts/joomla/content/category_default.php

To create a template override, copy it to:

(JOOMLA ROOT)/templates/(TEMPLATE)/html/layouts/joomla/content/category_default.php

Then, find the line that says:

Code:

<?php echo $displayData->loadTemplate($displayData->subtemplatename); ?>
and replace it with:

Code:

<?php$items = $displayData->get("items");$topLevelArticles = [];foreach ($items as $item){if ($item->catid == $category->id)$topLevelArticles[] = $item;}$displayData->set("items", $topLevelArticles);echo $displayData->loadTemplate($displayData->subtemplatename);?>
I hope future versions of Joomla will add this option to the Category List item. Until then, this code makes a nice fix.

Statistics: Posted by NetRod2 — Wed Dec 18, 2024 5:17 pm



Viewing all articles
Browse latest Browse all 1941

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>