Overview and Quick Setup

Once the XT-K2 Link Item plugin is installed and enabled, a new K2 Link Item management area is shown under the K2 article editor:

K2 Link Item management area

Clicking on the Select Items button, a new dialog to select items is shown to select associated articles:

K2 Link Item management area

After articles are associated to the main item, relationships can be managed in the K2 Link Item management area:

K2 Link Item associated articles

In the area below the associated items, several parameters allow to control how the relations are shown in the front-end site:

K2 Link Item parameters

Item View and Category View Templating

The associated items views generated in the front-end site can be overriden.

By default, these files are used to generate the views:

  • plugins/k2/xtlinkitem/tmpl/category.php
  • plugins/k2/xtlinkitem/tmpl/item.php

To override these views, new layouts can be created at template level. For example, creating these new files based on the default layouts:

  • templates/YOUR_TEMPLATE/html/plg_k2_xtlinkitem/category.php
  • templates/YOUR_TEMPLATE/html/plg_k2_xtlinkitem/item.php

Reference: Understanding_Output_Overrides

How to extend Item View and Category View templates for K2 Linked Articles

Templates have a main loop where the linked articles are visited. In each iteration, a linked articled is displayed. By default, the linked article has the attributes from #__k2_items to be shown.

In certain cases, there is a requirement to show additional information associated with the linked article. For instance, Tags from the linked article.

To extend the Item View Template to show linked article tags, the item view override must be created in templates/YOUR_TEMPLATE/html/plg_k2_xtlinkitem/item.php (around line 17) and this code to render tags must be added in the loop:

<div class="K2LinkedItemContainer">
    <?php
    foreach ($XTlinkedItems as $XTlinkedItem)
    {
        // Customization to load K2 model of the linked article
        $k2ModelItem = new K2ModelItem;
        $k2ModelItem = $k2ModelItem->prepareItem($XTlinkedItem, 'item', ''); 

In this way, now it is possible to show any value from the full K2 model, in the same way than it is implemented in the original K2 view (item.php). For example, the set of tags:

    <?php if($k2ModelItem->params->get('itemTags') && count($k2ModelItem->tags)): ?>
    <!-- Item tags -->
    <div class="itemTagsBlock">
        <span><?php echo JText::_('K2_TAGGED_UNDER'); ?></span>
        <ul class="itemTags">
            <?php foreach ($k2ModelItem->tags as $tag): ?>
            <li><a href="<?php echo $tag->link; ?>"><?php echo $tag->name; ?></a></li>
            <?php endforeach; ?>
        </ul>
        <div class="clr"></div>
    </div>
    <?php endif; ?>