I have Menu item “List All Categories”. Problem, that categories do not count articles from sub-categories and shows 0, should count all articles from all subcategories.
I can not add picture, so I will describe:
Category (0)
subcategory1 (1)
subacategory2 (1)
I want, that Category will count articles from sub-categories (in example should be 2).
Is anybody knows, how to fix it?
Any help is very appreciated.
Thank you in advance.
EDIT:
I am using 2.5 Joomla. No, I do not writing component/plugin/module.
I am using menu item:List All Categories (Menus->Main Menu-> Add new menu item-> List All Categories).
At last, I found place, where this function is described.
here, numitems is digit of articles in categories:
$subQuery = ' (SELECT cat.id as id FROM #__categories AS cat JOIN #__categories AS parent ' .
'ON cat.lft BETWEEN parent.lft AND parent.rgt WHERE parent.extension = ' . $db->quote($extension) .
' AND parent.published != 1 GROUP BY cat.id) ';
$query->leftJoin($subQuery . 'AS badcats ON badcats.id = c.id');
$query->where('badcats.id is null');
// i for item
if (isset($this->_options['countItems']) && $this->_options['countItems'] == 1)
{
if ($this->_options['published'] == 1)
{
$query->leftJoin(
$db->quoteName($this->_table) . ' AS i ON i.' . $db->quoteName($this->_field) . ' = c.id AND i.' . $this->_statefield . ' = 1'
);
}
else
{
$query->leftJoin($db->quoteName($this->_table) . ' AS i ON i.' . $db->quoteName($this->_field) . ' = c.id');
}
$query->select('COUNT(i.' . $db->quoteName($this->_key) . ') AS numitems');
}
and from my understanding, there I need to create similar to $subQuery, but this time it should count articles from sub-categories. but I have no idea, how to do that ;/
Any ideas?
Joomla!’s List All Categories will only show the count for articles in that specific category a sub-category will not be counted in a parent category. This is because a parent category can have articles of it’s own.
To show a total for all articles within a Category and it’s sub-categories would require either modifying the Joomla core
com_contentcomponent (any modification of core files should be considered bad) or creating a modified *copy com_content component* (which would be more efficient but probably more effort than you want) or creating a view override for thecategoriesview.Using the override will make the page display much heavier computation wise.
If you use an override all you will have to do is:
default_items.phpfrom/components/com_content/views/categories/tmpl/default_items.phpto/templates/your-template/html/com_content/categories/default_items.phpand2 – Count Sub-items
Insert this code after the
defined('_JEXEC') or die;line:Call the count function
Insert the line to call the count function after the second
ifstatement:Display the total including sub-categories
Change the line that echo’s the
$item->numitems;to something like this: