Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8374243
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:52:46+00:00 2026-06-09T14:52:46+00:00

I have Menu item List All Categories. Problem, that categories do not count articles

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-09T14:52:48+00:00Added an answer on June 9, 2026 at 2:52 pm

    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_content component (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 the categories view.

    Using the override will make the page display much heavier computation wise.

    If you use an override all you will have to do is:

    1. copy default_items.php from /components/com_content/views/categories/tmpl/default_items.php to /templates/your-template/html/com_content/categories/default_items.php and
    2. modify it to count the sub-items
    3. modify it to display the total count

    2 – Count Sub-items

    Insert this code after the defined('_JEXEC') or die; line:

    // Calculate number of items including sub-categories using a recursive anonymous function
    $countSubItems = function( $item ) use ( &$countSubItems ) {
        $children = $item->getChildren();
        if( count($children) == 0 ) {
            return $item->numitems;
        } else {
            $subItems = 0;
            foreach ($children as $child) {
                $subItems += $countSubItems($child);
            }
            return $subItems = $item->numitems + $subItems;
        }
    };
    

    Call the count function

    Insert the line to call the count function after the second if statement:

    $allItemsInclSubCats = $countSubItems($item);
    

    Display the total including sub-categories

    Change the line that echo’s the $item->numitems; to something like this:

    <dd><?php echo $item->numitems; ?> ( <?php echo $allItemsInclSubCats; ?> including sub-categories )</dd>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have to retrieve a list of menu item from a database and display
I have a simple unordered list with list items as menu item i created
I have a list of items, like a menu, where the current item has
I have a hardcoded li menu that is using filterable.js to filter a list
So I have bean named element that has a list of categories in and
I want to have a window's menu item maintain a list of open windows
I have a menu from actionLinks. All of the links have some id. According
I've run in to a bit of a problem. I have a menu list
I have a menu item Home in my main menu AND in my top
I have a menu item to which I add another item. Now I want

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.