3

I'm working on an override for com_content category blog view and need an unordered list of article tags in blog.php. Every tag should be wrapped in an <li>

<li>[tag]</li>
<li>[tag]</li>
<li>[tag]</li>
<li>[tag]</li>

After an intense search I found the following code:

<select>
            <option value=""><?php echo JText::_('JOPTION_SELECT_TAG'); ?></option>
            <?php echo JHtml::_('select.options', JHtml::_('tag.options', true, true), 'value', 'text', $this->state->get('filter.tag')); ?>
</select>

which gives me a dropdown box for all tags.

Screenshot

How can i change it to an unordered list?

Update:

I played around a lot but can't get the tag list at top of my category blog. The code from johanpw works, but only for each article item, so that I get duplicates. Is there any way to get every article tag from the selected category/subcategories only once in a list?

Maybe it has to be done by a template like the blog_children.php template to render all the tags which will be then loaded in the blog.php.

My coding skills are to low to solve this problem :(

2
  • Are you trying to get the tags used by each article on the blog.php, or just a list of all tags being used by Joomla? - for each article getting called onto blog.php, you would actually make this edit in blog_item.php - and it should even be there already.
    – Faye
    Commented Jun 20, 2016 at 23:38
  • @REactionFaye, thanks for your reply. actually i need all article tags listet within the chosen category. Commented Jun 22, 2016 at 8:32

2 Answers 2

1

Well, if I have got you right, you want to display in your various category blogs pages, all the tags that are involved in these categories. I would say that you would be better off using a module to display tags in your blog page. You will need to find or develop something that provides the possibility to filter by categories - not sure there is something like this already. Do a research in JED for Tags Modules, maybe you are lucky.

However, here is a quick and rather dirty workaround.

For each category blog page, you can gather all tags of the contained articles using the following:

  1. On top of the file start with:

    $tags = array();
    
  2. Inside the foreach of the leading articles, just below the $this->item = & $item;:

    $this->item = & $item;
    foreach ($this->item->tags->itemTags as $itemTag) {
        $tags[$itemTag->title] = $itemTag;
    }
    echo $this->loadTemplate('item');
    
  3. Same code inside the foreach of the intro articles:

    $this->item = & $item;
    foreach ($this->item->tags->itemTags as $itemTag) {
        $tags[$itemTag->title] = $itemTag;
    }
    echo $this->loadTemplate('item');
    
  4. You have now ended with an array of $tags.

    You can now loop over the array to get all the tags that are present for the articles available in that particular blog page.

    <div id="tagsListBox" class="tagsListBox">
        <ul id="tagsList" class="tagsList">
            <?php 
            foreach ($tags as $tag) { ?>
                <li><?php echo $tag->title; ?></li>
            <?php } ?>
        </ul>
    </div>
    

Wrap your list in a div and give to your elements special ids and classes, so to be able to position it everywhere you want in the page, using special css. Place it, outside of any of the foreach loops of leading/intro articles, e.g. above the start of the articles links section: <?php if (!empty($this->link_items)) : ?>

Again it's not the most elegant solution, but yet could give you what you want till you find something better.

1
  • Thanks a lot. This is the perfect solution!!!!!!!!! It works like a charm. Commented Jul 5, 2016 at 12:07
4

Try the following code and see if it gives you the output you want:

<ul>
  <?php foreach ($this->item->tags->itemTags as $tag) : 
    echo "<li>" . $tag->title . "</li>"; 
  endforeach; ?>
</ul>

Replace $tag->title with $tag->alias if you prefer to display the alias.

1
  • hi johanpw, this only shows me the ul /ul with no other output. do you have an other idea? Commented Jun 15, 2016 at 7:37

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.