0

I use mod_articles_category to display a list of categories with their articles.

I need to display the total of articles next to each category title. I've tried with <?php echo $item->numitems; ?> - found in com_content/categories - but it doesn't help.

defined('_JEXEC') or die;

use Joomla\CMS\Helper\ModuleHelper;
use Joomla\CMS\HTML\HTMLHelper;
use Joomla\CMS\Language\Text;
use Joomla\CMS\Layout\LayoutHelper;
use Joomla\CMS\Router\Route;
use Joomla\Component\Content\Site\Helper\RouteHelper;


if (!$list) {
    return;
}

?>

<ul class="row">
    <?php if ($grouped) : ?>
        <?php foreach ($list as $groupName => $items) : ?>
  
        <div class="col">
        <li>  
               
            <div class="mod-articles-category-group fs-3 fw-bold"><?php echo Text::_($groupName); ?>                 
                <span class="ps-3 text-muted fw-light fs-5"><?php echo $item->numitems; ?> articles</span>                   
            </div>
            
            <ul class="list-unstyled">
            
                <?php foreach ($items as $item) : ?>
                <li class="py-2">
                    <?php if ($params->get('link_titles') == 1) : ?>
                        <?php $attributes = ['class' => 'mod-articles-category-title ' . $item->active]; ?>
                        <?php $link = htmlspecialchars($item->link, ENT_COMPAT, 'UTF-8', false); ?>
                        <?php $title = htmlspecialchars($item->title, ENT_COMPAT, 'UTF-8', false); ?>
                        <img src="images/svg/caret.svg" alt="" width="13" height="13" class="pe-2"><?php echo HTMLHelper::_('link', $link, $title, $attributes); ?>
                    <?php else : ?>
                        <?php echo $item->title; ?>
                    <?php endif; ?>

                </li>
                <?php endforeach; ?>

            </ul>
            <p class="ms-3 pt-3"><i class="far fa-arrow-alt-circle-right pe-2"></i>See all articles about 
                <span class="mod-articles-category-category">
                    <?php echo $item->displayCategoryTitle; ?>
                </span>
            </p>
        </li>
         </div>
        <?php endforeach; ?>
    <?php else : ?>
        <?php $items = $list; ?>
        <?php require ModuleHelper::getLayoutPath('mod_articles_category', $params->get('layout', 'default') . '_items'); ?>
    <?php endif; ?>
</ul>

2 Answers 2

0

I suppose you want it with an override but if not really needed you can do easily with Article Anywhere plug-in and [count] info ;-)

1
  • Yes I want to acheive this with an override, not with an extension.
    – Mint
    Commented Feb 27, 2023 at 5:32
0

I've added count($items); in the loop to get the number of items:

        <div class="ms-3 mod-articles-category-group fs-3 fw-bold"><?php echo Text::_($groupName); ?>                
            <span class="ps-3 text-muted fw-light fs-5"><?php echo count($items); ?> articles</span>                 
        </div>
1
  • Please include an educational explanation with this snippet. Commented Feb 27, 2023 at 13:53

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.