0

I'm working on a override for com_tags List of all Tags, i want to change when clicking on the tag title the list of items (articles) will slide (accordion) instead of open in a new page. I create all the css and layout but i can't get the list for each tag. Tag list override Accordion

This the layout for *._items.php:

/**
 * @package     Joomla.Site
 * @subpackage  com_tags
 *
 * @copyright   Copyright (C) 2005 - 2018 Open Source Matters, Inc. All rights reserved.
 * @license     GNU General Public License version 2 or later; see LICENSE.txt
 */

defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');

JHtml::_('behavior.core');
JHtml::_('formbehavior.chosen', 'select');

// Get the user object.
$user = JFactory::getUser();

// Check if user is allowed to add/edit based on tags permissions.
$canEdit      = $user->authorise('core.edit', 'com_tags');
$canCreate    = $user->authorise('core.create', 'com_tags');
$canEditState = $user->authorise('core.edit.state', 'com_tags');

$n = count($this->items);

?>
<div class="accordion" id="accordionTags">
    <?php if ($this->items == false || $n === 0) : ?>
        <p><?php echo JText::_('COM_TAGS_NO_TAGS'); ?></p>
    <?php else : ?>
        <?php foreach ($this->items as $i => $item) : ?>
            <?php if ((!empty($item->access)) && in_array($item->access, $this->user->getAuthorisedViewLevels())) : ?>
            <!--Card Start -->
            <div class="card">
                <!-- Row Heading -->
                <div id="tagRowHeading-<?php echo $i;?>" class="card-header cat-list-row<?php echo $i % 2; ?>">
                    <h4>
                        <button class="btn-btn-link" type="button" data-toggle="collapse" data-target="#collapseCard-<?php echo $i;?>" data-parent="#accordionTags" aria-expanded="false" aria-controls="collapseCard-<?php echo $i;?>">
                                <?php echo $this->escape($item->title); ?>  
                        </button> 
                    </h4>
                </div>
                <!-- End Card Heading -->
                <!-- Card Body -->
                <div id="collapseCard-<?php echo $i;?>" class="collapse" aria-labelledby="tagRowHeading-<?php echo $i;?>" data-parent="#accordionTags">
                    <div class="card-body">
                        <?php echo $this->loadTemplate('items_tag'); ?>                     
                    </div>
                </div>
                <!-- End Card Body -->
            </div>
            <!-- End card -->   
            <?php endif; ?>
            <div class="caption">
                <?php if ($this->params->get('all_tags_show_tag_description', 1)) : ?>
                    <span class="tag-body">
                        <?php echo JHtml::_('string.truncate', $item->description, $this->params->get('all_tags_tag_maximum_characters')); ?>
                    </span>
                <?php endif; ?>
            </div>
        <?php endforeach; ?>
    <?php endif; ?>
    <?php // Add pagination links ?>
    <?php if (!empty($this->items)) : ?>
        <?php if (($this->params->def('show_pagination', 2) == 1 || ($this->params->get('show_pagination') == 2)) && ($this->pagination->pagesTotal > 1)) : ?>
            <div class="pagination">
                <?php if ($this->params->def('show_pagination_results', 1)) : ?>
                    <p class="counter pull-right">
                        <?php echo $this->pagination->getPagesCounter(); ?>
                    </p>
                <?php endif; ?>
                <?php echo $this->pagination->getPagesLinks(); ?>
            </div>
        <?php endif; ?>
    <?php endif; ?>
</div>

And for the list of articles(loadTemplate('items_tag')):

    <?php
    defined('_JEXEC') or die;

JHtml::_('behavior.core');
JHtml::_('formbehavior.chosen', 'select');

$n         = count($this->items);
$listOrder = $this->escape($this->state->get('list.ordering'));
$listDirn  = $this->escape($this->state->get('list.direction'));

$articleTag = new JHelperTags;
$articleTag->getItemTags('com.content.article', $item->id);

JFactory::getDocument()->addScriptDeclaration("
        var resetFilter = function() {
        document.getElementById('filter-search').value = '';
    }
");

?>
<div id=tagtest>
    <?php echo JLayoutHelper::render('joomla.content.tags', $articleTag->itemTags); ?>
</div>

<ul>
    <?php foreach ($this->items as $i => $item) : ?>
        <?php if ($this->items[$i]->core_state == 0) : ?>
            <li class="system-unpublished cat-list-row<?php echo $i % 2; ?>">
        <?php else : ?>
            <li class="cat-list-row<?php echo $i % 2; ?>">
        <?php endif; ?>
                <a href="<?php echo JRoute::_(TagsHelperRoute::getItemRoute($item->content_item_id, $item->core_alias, $item->core_catid, $item->core_language, $item->type_alias, $item->router)); ?>">
                        <?php echo $this->escape($item->core_title); ?>
                    </a>
                    <?php if ($item->core_state == 0) : ?>
                        <span class="list-published label label-warning">
                            <?php echo JText::_('JUNPUBLISHED'); ?>
                        </span>
                    <?php endif; ?> -->
            </li>
    <?php endforeach; ?>
</ul>
  • Please show your code. – TryHarder Jun 12 '18 at 12:18
0

Use Tag model.

$tagModel = JModelLegacy::getInstance('Tag', 'TagsModel', array('ignore_request' => true));
$tagParams = new \Joomla\Registry\Registry();
$tagModel->setState('params', $tagParams);
$tagModel->setState('tag.id', $item->id);
$tagItems = $tagModel->getItems();
  • Thank you for your response, could you please be more specific. Where to use the code. And what is the echo that i need – dg82 Jun 17 '18 at 9:48
0

First, some explanations of your code. Since this is done inside tag loop ($this->items holds tags), $item variable is current tag in the loop. So this tries to get article tags but you're inputting tag ID as article ID:

$articleTag = new JHelperTags;
$articleTag->getItemTags('com.content.article', $item->id);

Anyways, you don't need this unless you also want article tags displayed so structure would be like this: Tag -> Article -> Article Tags.

Using $this->items inside items_tag layout means running the same tag loop again. Instead you need to get tagged items.

This is what my snippet does. Place it somewhere in the tag loop (items_tag layout is fine). and use $tagItems to access tagged items.

This is a what items_tag layout could look like:

<?php

defined('_JEXEC') or die;

$tagModel = JModelLegacy::getInstance('Tag', 'TagsModel', array('ignore_request' => true));
$tagParams = new \Joomla\Registry\Registry();
$tagModel->setState('params', $tagParams);
// Set tag filter
$tagModel->setState('tag.id', $item->id);
$tagItems = $tagModel->getItems();

if (!empty($tagItems)) : ?>
    <ul>
        <?php foreach ($tagItems as $i => $tagItem) : ?>
            <?php if ($tagItem->core_state == 0) : ?>
                <li class="system-unpublished cat-list-row<?php echo $i % 2; ?>">
            <?php else : ?>
                <li class="cat-list-row<?php echo $i % 2; ?>">
            <?php endif; ?>
                    <a href="<?php echo JRoute::_(TagsHelperRoute::getItemRoute($tagItem->content_item_id, $tagItem->core_alias, $tagItem->core_catid, $tagItem->core_language, $tagItem->type_alias, $tagItem->router)); ?>">
                            <?php echo $this->escape($tagItem->core_title); ?>
                        </a>
                        <?php if ($tagItem->core_state == 0) : ?>
                            <span class="list-published label label-warning">
                                <?php echo JText::_('JUNPUBLISHED'); ?>
                            </span>
                        <?php endif; ?>
                </li>
        <?php endforeach; ?>
    </ul>
<?php endif; ?>
  • Thank you, you understand what i'm trying to do and i was pretty close to your solution but still the $tagItems is empty. – dg82 Jun 20 '18 at 8:15

Your Answer

By clicking "Post Your Answer", you agree to our terms of service, privacy policy and cookie policy

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