Skip to content

Instantly share code, notes, and snippets.

@phproberto
Created December 7, 2012 11:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save phproberto/4232595 to your computer and use it in GitHub Desktop.
Save phproberto/4232595 to your computer and use it in GitHub Desktop.
Trick to make com_taxonomy use content blog templates

Force com_taxonomy to use content category blog templates.

This method uses a hidden menu item to customize the com_taxonomy tag results.

Demo

You can see it in action in:

http://digitaldisseny.com/en/component/taxonomy/prestashop

How to use it

First of all you have to create a menu item of type "Category Blog". You will use this item to set the params for the com_taxonomy tag view as number of leading items, intro items, show page title, show category title, etc.

After that you have to replace:

$menuitemid = 115;

with the id of the menu item that you have created.

You have to save this file as:

templates/YOUR_TEMPLATE_NAME/html/com_taxonomy/tag/default.php

Extra customization

You can use any desired layout just replacing:

$this->_layout = 'blog';

with other view name like:

$this->_layout = 'default'

<?php
/**
* Customized tag/default.php file to use blog view for tag listings
*/
defined('_JEXEC') or die('Restricted access');
JLoader::import('joomla.application.component.model');
// INSERT HERE THE MENU USED TO LOAD VIEW PARAMS
$menuitemid = 115;
// Get com_content params
$contentParams = JComponentHelper::getParams( 'com_content' );
$appParams = JFactory::getApplication()->getParams();
$appParams->merge( $contentParams);
JHtml::addIncludePath(JPATH_SITE . '/components/com_content/helpers');
JLoader::import( 'articles', JPATH_SITE . '/components/com_content/models' );
// Load content language
$lang = JFactory::getLanguage();
$lang->load('com_content', JPATH_SITE, null, true);
// Initialize item type arrays
$this->lead_items = array();
$this->intro_items = array();
$this->link_items = array();
if (count($this->results) > 0)
{
$ids = array();
foreach ($this->results as $item)
{
$ids[] = reset(explode(':', $item->slug));
}
// Get full items from articles model
$model = JModelLegacy::getInstance('Articles', 'ContentModel', array('ignore_request' => true));
if ($menuitemid)
{
$menu = JSite::getMenu();
$menuparams = $menu->getParams( $menuitemid );
$appParams->merge( $menuparams );
}
$model->setState('params', $appParams);
$model->setState('filter.article_id', $ids);
$items = $model->getItems();
// Params to generate article arrays
$numLeading = $appParams->get('num_leading_articles', 1);
$numIntro = $appParams->get('num_intro_articles', 1);
$numLinks = $appParams->get('num_links', 1);
// Params for view
$this->columns = $appParams->get('num_columns', 1);
$this->pagination = $model->getPagination();
foreach ($items as $pos => $item)
{
// Generate slug
$item->slug = $item->alias ? ($item->id . ':' . $item->alias) : $item->id;
// Create empty events properties
$item->event = new stdClass;
$item->event->afterDisplayTitle = null;
$item->event->beforeDisplayContent = null;
$item->event->afterDisplayContent = null;
$item->event->beforeDisplayContent = null;
if ($numLeading)
{
$this->lead_items[] = $item;
$numLeading--;
}
elseif ($numIntro)
{
$this->intro_items[] = $item;
$numIntro--;
}
elseif ($numLinks)
{
$this->link_items[] = $item;
$numLinks--;
}
}
}
// Create required category properties
$this->category->id = null;
$this->category->title = $this->searchword;
$this->category->description = '';
// Use generated params
$this->params = $appParams;
// Force content category blog view
$tplOverride = JPATH_SITE . '/templates/'. JFactory::getApplication()->getTemplate() . '/html/com_content/category/';
$tplDefault = JPATH_SITE . '/components/com_content/views/category/tmpl/';
$this->_layout = 'blog';
$this->_path['template'] = array($tplOverride, $tplDefault);
$tplFile = file_exists($tplOverride . $this->_layout . '.php') ? $tplOverride . $this->_layout . '.php' : $tplDefault . $this->_layout . '.php';
require_once $tplFile;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment