Skip to content

Instantly share code, notes, and snippets.

@b2z
Last active July 10, 2020 12:10
Show Gist options
  • Save b2z/065442474ffb55db95d0d5afd551381a to your computer and use it in GitHub Desktop.
Save b2z/065442474ffb55db95d0d5afd551381a to your computer and use it in GitHub Desktop.
Tags layout override with the count of articles for each tag. Put it to /templates/{your_template}/html/layouts/joomla/content/tags.php. Tested on Joomla 3.
<?php
/**
* @package Joomla.Site
* @subpackage Layout
*
* @copyright Copyright (C) 2005 - 2019 Open Source Matters, Inc. All rights reserved.
* @license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('JPATH_BASE') or die;
use Joomla\CMS\Factory;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\Registry\Registry;
JLoader::register('TagsHelperRoute', JPATH_BASE . '/components/com_tags/helpers/route.php');
$authorised = JFactory::getUser()->getAuthorisedViewLevels();
?>
<?php if (!empty($displayData)) : ?>
<ul class="tags inline">
<?php foreach ($displayData as $i => $tag) : ?>
<?php if (in_array($tag->access, $authorised)) : ?>
<?php $tagParams = new Registry($tag->params); ?>
<?php $link_class = $tagParams->get('tag_link_class', 'label label-info'); ?>
<li class="tag-<?php echo $tag->tag_id; ?> tag-list<?php echo $i; ?>" itemprop="keywords">
<a href="<?php echo JRoute::_(TagsHelperRoute::getTagRoute($tag->tag_id . ':' . $tag->alias)); ?>" class="<?php echo $link_class; ?>">
<?php echo $this->escape($tag->title); ?>
</a>
<?php // Get the list of items for tag
$result = Factory::getDbo()
->setQuery(TagsHelper::getTagItemsQuery($tag->tag_id, 1))
->loadObjectList();
if (!empty($result)) : ?>
(<?php echo count($result);?>)
<?php endif; ?>
</li>
<?php endif; ?>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment