2

How can I get the associated articles programmatically in my custom component function?

I have my custom component and I am creating a new article for a multilingual site, so I need to associate articles of different languages.

1 Answer 1

2

You can use JLanguageAssociations::getAssociations. This function will return an array containing associated items. You can also check if the language filter Items Associations parameter is enabled using JLanguageAssociations::isEnabled().

Here's an example from ROOT/administrator/components/com_content/models/article.php:

// Load associated content items
$app = JFactory::getApplication();
$assoc = JLanguageAssociations::isEnabled();

if ($assoc)
{
    $item->associations = array();

    if ($item->id != null)
    {
        $associations = JLanguageAssociations::getAssociations('com_content', '#__content', 'com_content.item', $item->id);

        foreach ($associations as $tag => $association)
        {
            $item->associations[$tag] = $association->id;
        }
    }
}

return $item;

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.