Web357 logo

Multiple Categories for K2 - Frequently Asked Questions


How to display the K2 multiple categories in SP Page Builder pages?

The K2 Multiple Categories Web357 Plugin is now integrated with the SP Page Builder pages

In order to show the multiple categories in SP Page Builder pages, you should follow the below instructions.

STEP 1

Open the file /components/com_sppagebuilder/addons/articles/site.php

FIND (line ~168):

if($show_category) {
    if ($resource == 'k2') {
        $item->catUrl = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid.':'.urlencode($item->category_alias))));
    } else {
        $item->catUrl = JRoute::_(ContentHelperRoute::getCategoryRoute($item->catslug));
    }
    $output .= '' . $item->category . '';
}

REPLACE WITH:

/*if($show_category) {
    if ($resource == 'k2') {
        $item->catUrl = urldecode(JRoute::_(K2HelperRoute::getCategoryRoute($item->catid.':'.urlencode($item->category_alias))));
    } else {
        $item->catUrl = JRoute::_(ContentHelperRoute::getCategoryRoute($item->catslug));
    }
    $output .= '' . $item->category . '';
}*/

// BEGIN: Multiple Categories for K2, by Web357
if($show_category && $resource == 'k2')
{
    JPluginHelper::importPlugin('k2', 'k2multiplecategories');
    $w357_dispatcher = JDispatcher::getInstance();
    $k2multiplecategories = $w357_dispatcher->trigger('onK2AfterDisplayContentAdvanced', array($item));
    if (!empty($k2multiplecategories) && is_array($k2multiplecategories))
    {
        $k2multiplecategories_links_arr = explode(',', $k2multiplecategories[0]);
        $output_arr = array();
        foreach ($k2multiplecategories_links_arr as $link)
        {
            $output_arr[] = '<span class="sppb-meta-category">'.$link.'</span>';
        }
        $output .= implode(', ', $output_arr);
    }
}
// END: Multiple Categories for K2, by Web357

STEP 2

Open the file /components/com_sppagebuilder/helpers/k2.php

FIND (line ~44):

->join('LEFT', $db->quoteName('#__k2_categories', 'b') . ' ON (' . $db->quoteName('a.catid') . ' = ' . $db->quoteName('b.id') . ')');

REPLACE WITH:

//->join('LEFT', $db->quoteName('#__k2_categories', 'b') . ' ON (' . $db->quoteName('a.catid') . ' = ' . $db->quoteName('b.id') . ')');
// BEGIN: Multiple Categories for K2, by Web357
->join('LEFT', $db->quoteName('#__k2_multiple_categories', 'mcats') . ' ON (' . $db->quoteName('a.id') . ' = ' . $db->quoteName('mcats.item_id') . ')')
->join('LEFT', $db->quoteName('#__k2_categories', 'b') . ' ON (' . $db->quoteName('mcats.cat_id') . ' = ' . $db->quoteName('b.id') . ')');
$query->group($db->quoteName('mcats.item_id'));
// END: Multiple Categories for K2, by Web357

Stay tuned

We are always working on something new and exciting so make sure to subscribe to our newsletter and be the first to know.