6

I am trying to make a module to bring back all articles in a category "holidays" that have a tag of "cuba"

All the examples I can find are tag clouds or getting tags for the current article.

Does anyone have any code or pointers to understanding the Tag tables so I could write the SQL. The end result is a travel site showing other holidays with tag x.

thanks

  • Now up to 1000 views on this question, I wonder if its worth me submitting a PR to the Joomla project to add this as a core module. – tristanbailey Jul 27 '15 at 15:28
2

Some nice chap has already created a module that displays articles with a certain TAG so no hacking involved,

I suppose it would be simple (depending on your coding experience) to add a new parameter of CATEGORY to the module XML and alter the model to incorporate this new parameter as well to this and build your own custom module

Custom module to pull in articles of a certain TAG

  • Thanks, I found that with a random google query on the getTagItemsQuery method after doing this question, I'd not seen it the weeks I'd been looking before. – tristanbailey Jul 18 '14 at 13:03
  • 1
    If you get round to adding the category filter why not fork the project ;-) Good Luck – MOLEDesign Jul 18 '14 at 13:20
  • Just seen this in a search result - I forked this a while ago and tidied it up / added in some additional options. Not sure if it helps, but have a gander at github.com/muckypuddle/joomla-tags-selected if you're interested. – codinghands Mar 3 '15 at 12:20
5

You can easily get all articles tagged with a tag, but not from a specific category, so you'd have to check for that in a step 2.

In JHelperTags (defined in libraries\cms\helper) there is a method

public function getTagItemsQuery( $tagId, $typesr = null, $includeChildren = false, $orderByOption = 'c.core_title', $orderDir = 'ASC', $anyOrAll = true, $languageFilter = 'all', $stateFilter = '0,1' )

Assuming you know the id of your tag, you'd call the function with

$tagsHelper = new JHelperTags;
$articles = $tagsHelper->getTagItemsQuery( $tagId, 'com_content.article', true, 'c.core_publish_up', 'DESC', true, 'all', '1' );

Then just filter articles you need.

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.