i will get tags from a specific parent id in each article

my Tags list :

. Id .... Name

Post id 600 has 3 tags (ids 3, 5, and 6). I will show only tags with parent id 4 How can I do it???

  • Welcome to JSE. Please take our tour while you wait for support. If you have made any attempt to self-solve, please include your efforts as an edit of the question. Please continue to work on this issue yourself -- if you manage to resolve this problem yourself, please post an educational answer.
    – mickmackusa
    Sep 9 '20 at 21:21

There are a couple of ways you could do it, both involving examining the article tags which com_content produces, comparing them with the tags which you want to keep, and discarding the tags which don't match.

You can do this either by creating an override of the com_content layout display.php for displaying an article (as described in https://docs.joomla.org/J3.x:How_to_use_the_Template_Manager#Creating_Overrides) or you could use a content plugin which is triggered by onContentPrepare and remove the unwanted tags that way.

Either way, you should use the TagsHelper API to get the tags associated with the specific parent, and the searchTags() method will do this for you. Examples of calling this function are given in the Tags API Guide.

The basic plugin code which will do something like what you want is below. You may need to adapt it slightly - for example, this matches all descendants of tag with id=4, not just immediate children, and there are views other than com_content.article where articles are output. I'm not guaranteeing that it's totally bug-free!

defined( '_JEXEC' ) or die;
use Joomla\CMS\Helper\TagsHelper;
use Joomla\CMS\Factory;

class plgContentLimittags extends JPlugin
     public function onContentPrepare($context, &$article, &$params, $page = 0)
        $parts = explode(".", $context);
        $app = Factory::getApplication();
        if ($app->isClient('site') && isset($parts[0]) && $parts[0] == "com_content" && isset($parts[1]) && $parts[1] == "article" && isset($article->id, $article->tags, $article->tags->itemTags))
            $filters = array('parent_id' => 4);
            $allowedTags = TagsHelper::searchTags($filters);
            foreach ($article->tags->itemTags as $index => $tag)
                $found = false;
                foreach ($allowedTags as $allowedTag)
                    if ($tag->tag_id == $allowedTag->value)
                        $found = true;
                if (!$found)
        return true;

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.