Extended Category Level in Magento - magento

How to Extend Category Level in Magento Frontend Site:
Insert this code* under the First Level of the category. In my case, the site's category navbar is located on header.phtml
*The code starts at: Level 2nd Start
*improving this code is highly appreciated.
(mikequibin/app/design/frontend/mikequibin/default/template/page/html/header.phtml)
<div class="header-category-menu" style="background: none;">
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::getSingleton('catalog/layer')->getCurrentCategory()->getId(); ?>
<?php if (count($_categories) > 0): ?>
<div class="menu-bg">
<ul class="menu clearfix">
<?php foreach($_categories as $_category): ?>
<?php $class = 'link'; ?>
<?php if($_category->getEntityId() == 13 || $_category->getEntityId() == 36): ?>
<?php $class = 'link sale'; ?>
<?php endif; ?>
<?php $class .= $currentCategory==$_category->getEntityId() ? ' active' : NULL; ?>
<li class="<?php echo $class; ?> menu-nav" data-id="<?php echo $_category->getId(); ?>">
<?php if($_category->getId() != 36) : ?>
<i class="icon-caret-down"></i>
<?php endif; ?>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<span><?php echo $_category->getName() ?></span>
</a>
<!-- First Level Start --!>
<?php
$subCategories = Mage::getModel('catalog/category')->load($_category->getId());
$subCategories = $subCategories->getChildrenCategories();
?>
<?php if(count($subCategories) != 0): ?>
<ul class="submenu">
<?php foreach($subCategories as $i => $subCategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($subCategory); ?>">
<i class="icon-chevron-right"></i><?php echo $subCategory->getName(); ?>
<!-- Second Level Start --!>
<?php if($_category->getIsActive()): ?>
<?php
$subCategories2 = Mage::getModel('catalog/category')->load($subCategory->getId());
$subCategories2 = $subCategories2->getChildrenCategories();
?>
<?php if(count($subCategories2) != 0): ?>
<?php foreach($subCategories2 as $k => $subCategory2): ?>
<li style="padding-left:20px;">
<a href="<?php echo $_helper->getCategoryUrl($subCategory2); ?>">
<?php echo $subCategory2->getName(); ?>
<!-- Third Level Start --!>
<?php if($_category->getIsActive()): ?>
<?php
$subCategories3 = Mage::getModel('catalog/category')->load($subCategory2->getId());
$subCategories3 = $subCategories3->getChildrenCategories();
?>
<?php if(count($subCategories3) != 0): ?>
<?php foreach($subCategories3 as $l => $subCategory3): ?>
<li style="padding-left:30px;">
<a href="<?php echo $_helper->getCategoryUrl($subCategory3); ?>">
<?php echo $subCategory3->getName(); ?>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
<!-- Third Level End --!>
</a>
</li>
<?php endforeach; ?>
<?php endif; ?>
<?php endif; ?>
<!-- Second Level End --!>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<!-- First Level End --!>
</li>
<?php endforeach; ?>
</ul>
</div>
<?php endif; ?>
</div>

$_helper = Mage::helper('catalog/category');
$_categories = $_helper->getStoreCategories();
$html = '';
if (count($_categories) > 0) {
$html .= '<ul>';
foreach($_categories as $_category) {
$html .= '<li>';
$html .= ''.$_category->getName().'';
$html .= getRecursiveHtml($_category);
$html .= '</li>';
}
$html .= '</ul>';
}
function getRecursiveHtml($_category,$html='') {
$_category = Mage::getModel('catalog/category')->load($_category->getId());
$child = $_category->getChildrenCategories();
if (count($child) > 0) {
$html .= '<ul>';
foreach($child as $_child) {
$html .= '<li>';
$html .= ''.$_child->getName().'';
$html = getRecursiveHtml($_child,$html);
$html .= '</li>';
}
$html .= '</ul>';
}
return $html;
}
echo $html;

Related

How to create Custom Menu in magento with active and deactive class for category?

I need a custom categories menu in magento. and i want a active class on active category. when i click on category then that category should be add active class.
(i) First of all create your custom category from admin panel
(ii)Then pass the category id in getCategories() function in code
Try this code,it works for me.I hope this work for you.
<?php
$children = Mage::getModel('catalog/category')->getCategories(2);
?>
<div class="menusecond">
<ul id="second menu">
<?php
foreach ($children as $category) { ?>
<li class="mymenu">
<?php $catId = $category->getId(); ?>
<?php $cat = Mage::getModel('catalog/category')->load($catId); ?>
<a href="<?php echo $cat->getUrl(); ?>">
<?php echo $cat->getName(); ?>
</a>
</li>
<?php
}
?>
</ul>
</div>
I found the solution. we can identify current category by category getUrlKey.
<?php
$_helper = Mage::helper('catalog/category');
$_categories = Mage::getResourceModel('catalog/category_collection')
->addAttributeToSelect('*')
->addAttributeToFilter('is_active', 1) //only active categories
->addAttributeToFilter('include_in_menu', 1);
$currentCategory = Mage::registry('current_category') ;
$rootCategoryId = Mage::app()->getStore()->getRootCategoryId();
$rootCategory = Mage::getModel('catalog/category')->load($rootCategoryId);
$childIds = explode(',',$rootCategory->getChildren()); ?>
<div class="row">
<?php if (count($childIds) > 0): ?>
<ul>
<?php foreach($childIds as $_category):
$_category = Mage::getModel('catalog/category')->load($_category); ?>
<?php if ($_category->getIncludeInMenu()) { ?>
<?php $allsubchild = explode(',',$_category->getChildren());?>
<?php foreach($allsubchild as $_sub): ?>
<?php endforeach; ?>
<li class="<?php if (strpos($_SERVER['REQUEST_URI'], $_category->getUrlKey()) !== false){ echo "active";} ?>">
<?php echo $_category->getName() ?>
<?php } ?>
<ul>
<?php $ss = 0; foreach($allsubchild as $_sub):
$_subcategory = Mage::getModel('catalog/category')->load($_sub);
?>
<?php if ($_subcategory->getIncludeInMenu()) { ?>
<?php
$uri = $_category->getUrlKey();
$uri .= "/";
$uri .= $_subcategory->getUrlKey(); // echo $uri; ?>
<li class="<?php if($_subcategory->getChildrenCount()) { echo "has-dropdown1"; }?> <?php if (strpos($_SERVER['REQUEST_URI'], $uri) !== false){ echo "active";} ?>">
<?php echo $_subcategory->getName(); ?>
<?php $suren = explode(',',$_subcategory->getChildren());?>
<ul>
<?php
foreach($suren as $suren1){
$suren11 = Mage::getModel('catalog/category')->load($suren1);
$_suren1id = $suren11->getId();
$internet_count = Mage::getModel('catalog/category')->load($_suren1id)->getProductCount();
if ($internet_count > 0) {
if ($suren11->getIncludeInMenu()) { ?>
<?php
$uri1 = $uri;
$uri1 .= "/";
$uri1 .= $suren11->getUrlKey(); // echo $uri1; ?>
<li>
<a class="<?php if (strpos($_SERVER['REQUEST_URI'], $uri1) !== false){ echo "active";} ?>" href="<?php echo $suren11->getUrl(); ?>" title="<?php echo $suren11->getName(); ?>"><?php echo $suren11->getName(); ?></a>
</li>
<?php } ?>
<?php } ?>
<?php } ?>
</ul>
</li>
<?php }?>
<?php $ss++; endforeach; ?>
</ul>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</div>
Goto app/design/frontend/rwd/default/template/page/html and open topmenu.phtml file. find this code <?php if($_menu): ?>
<nav id="nav">
<ol class="nav-primary">
<?php echo $_menu ?>
</ol>
</nav>
<?php endif ?>
this code will output you the categories in the form of top menu if you don't use any categories hide this code or else paste this code before or after this code.
<ul>
<li>HOME</li>
<li>ABOUT US</li>
<li>your_page_name</li>
<li>your_page_name</li>
</ul>

display category on left side bar in magento

I just want to display category and subcategory on left side bar, i have a code that work according to my need but this code only display name of the category it didn't get url for a particular category name.
code :-
<?php
$_categories = Mage::getBlockSingleton('catalog/navigation');
foreach ($_categories->getStoreCategories() as $_category) {
$category = Mage::getModel('catalog/category');
$category->load($_category->getId());
$subcategories = explode(',', $category->getChildren());
?>
<?php
foreach ($subcategories as $subcategoryId) {
$category->load($subcategoryId);
echo '<li>' . $category->getName() . '</li>';
}
?>
<?php
}
?>
It only display name for each subcategory but can't linked it with particular url for each sub category properly. suggest me where i did mistake.
Instead of using category object you need to load the subcategory again ex:
<?php
foreach ($subcategories as $subcategoryId) {
//$category->load($subcategoryId); instead
$subcategory = Mage::getModel("catalog/category")->load($subcategoryId);
echo '<li>' . $subcategory->getName() . '</li>';
}
?>
Second and good method as follows :
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul>
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<ul>
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
Please note that you may need to tweak some bit of code above.
Hope this helps.

Get a category in magento

I have this kind of categories in magenta:
-MotoCross
->Parts1 ->sub-parts
->Parts2 ->sub-parts
->Parts3 ->sub-parts
-Quad
->Parts1 ->sub-parts
->Parts2 ->sub-parts
->Parts3 ->sub-parts
For now i have MotoCross and Quad printed on screen and their child (parts1,2,3) but I would like to have Part1 and them sub parts printed on screen.
I don't know how to do, see my code bellow:
---------------------------EDIT---------------------------
Now I have the current category categories, but i don't know how two have current category categories categories. You're still here ? :P
<?php
$object = new Mage_Catalog_Block_Navigation();
$actualCategoryId = $object->getCurrentCategory()->getId();
$actualCategory = Mage::getModel('catalog/category')->load($actualCategoryId);
$subCategories = explode(',', $actualCategory->getChildren());
?>
<div id="categories_list">
<ol>
<?php
foreach ( $subCategories as $subCategoryId )
{
$category = Mage::getModel('catalog/category')->load($subCategoryId);
if ( $category->getIsActive() )
{ ?>
<li class="second_level_cat">
<?php
echo ''.$category->getName().' ';
?>
</li>
<?php
}
}
?>
</ol>
</div>
Thanks for your help.
It's something like this.
<div id="categories_list">
<ol>
<?PHP foreach ($catIds as $cid): ?>
<?PHP $_category = Mage::getModel('catalog/category')->load($cid); ?>
<?PHP if($_category->getLevel() == 2 ) : ?>
<li class="second_level_cat">
<a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->htmlEscape($_category->getName()) ?></a>
</li>
<?php
$cat = Mage::getModel('catalog/category')->load($_category->getId());
$childrens = $cat->getChildren();
if($childrens)
{
$childs=explode(",",$childrens);
foreach($childs as $child){
$cat_child = Mage::getModel('catalog/category')->load($child);
?>
<li class="third_level_cat">
<a href="<?php echo $this->getCategoryUrl($cat_child) ?>"<?php if ($this->isCategoryActive($cat_child)): ?> class="current"<?php endif; ?>><?php echo ucfirst(strtolower($this->htmlEscape($cat_child->getName()))) ?></a>
</li>
<?php
}
}
?>
<?php endif; ?>
<?php endforeach ?>
</ol>
</div>
Here is code
$cats = Mage::getModel('catalog/category')->load(2)->getAllChildren(); // 2 = Root Category
$catIds = explode(',',$cats);
Select Category :
<select id="_cid" name="_cid">
<?PHP foreach ($catIds as $cid){ ?>
<?PHP $_category = Mage::getModel('catalog/category')->load($cid); ?>
<?PHP if($_category->getLevel() == 3 ) { ?>
<option value="<?PHP echo $_category->getId() ?>"> <?PHP echo $_category->getName() ?></option>
<?PHP } ?>
<?PHP if($_category->getLevel() == 4 ) { ?>
<option value="<?PHP echo $_category->getId() ?>"> <?PHP echo $_category->getName() ?></option>
<?PHP } ?>
<?PHP } ?>
</select>

How to show children's subcategorie's of current categorie in Magento

I am trying to get my big catalog somewhat tablet friendly by offering an selection of tabs with sublevel links for my seperate categories. So if a user clicks a (1st level)head category it needs to display a nr of blocks which hold the picture, description and url of each direct child and a list of all the underlying (3rd level) child categories of the shown (2nd level) categorie. Would any off you guys be so kind to check my code?
<?php
$layer = Mage::getSingleton('catalog/layer');
$_category = $layer->getCurrentCategory();
$_categories = $_category->getCollection()
->addAttributeToSelect(array('url_key','name','image','all_children','is_anchor','description'))
->addAttributeToFilter('is_active', 1)
->addIdFilter($_category->getChildren())
->setOrder('position', 'ASC')
->joinUrlRewrite();
?>
<?php $children = explode( ",", $this->getCurrentCategory()->getChildren() ); ?>
<ul class="category-grid">
<div class="category-list">
<?php foreach( $children as $child ): ?>
<?php $_child = Mage::getModel( 'catalog/category' )->load( $child ); ?>
<li class="item">
<img title="<?php echo $this->htmlEscape($_child->getName()) ?>" src="<?php echo $this->htmlEscape($_child->getImageUrl()) ?>" alt="<?php echo $this->htmlEscape($_child->getName()) ?>" />
<div class="subcategory-title">
<?php echo $this->htmlEscape($_child->getName()) ?>
</div>
<div class="description-block"> <?php echo $_child->getDescription(); ?></div>
<div class="children-links"><?php
$_helper = Mage::helper("catalog/category");
$rootCat = Mage::app()->getStore()->getRootCategoryId();
$current = Mage::registry('current_category');
if ($child){
//look for anchestor
$parentid = $child->getParentId();
$parent = Mage::getModel("catalog/category")->load($parentid);
if($parentid != $rootCat)
{
//find the anchestor
show_cat($parent,$_helper,$rootCat);
}else{
//is root
$_subcategories = $child->getChildrenCategories();
echo $_child->getAll_Children();
if(count($_subcategories)>0){
echo '<ul>';
foreach($_subcategories as $_category){
echo '<li>';
echo ''.$_category->getName().'';
if($child->getId() == $_category->getId()){
$current = Mage::registry('current_category');
if ($current){
//handle current
$_current_subcategories = $current->getChildrenCategories();
if(count($_current_subcategories)>0){
//the current cat has childrens
echo '<ul>';
foreach($_current_subcategories as $_sub_category){
echo '<li>';
echo ''.$_sub_category->getName().'';
echo '</li>';
}
echo '</ul>';
}else{
//the current cat has no childrens
$current_parent = $current->getParentId();
$current_parent = Mage::getModel("catalog/category")->load($current_parent );
$_current_subcategories = $current_parent ->getChildrenCategories();
echo '<ul>';
foreach($_current_subcategories as $_sub_category){
echo '<li>';
echo ''.$_sub_category->getName().'';
echo '</li>';
}
echo '</ul>';
}
}
}
echo '</li>';
}
echo '</ul>';
}
}
}
?>
</div>
</li>
<?php endforeach ?>
</div>
</ul>
you can this by the below code and also refer link at bottom
you could be go with this
<?php $_helper = Mage::helper('catalog/category') ?>
<?php $_categories = $_helper->getStoreCategories() ?>
<?php $currentCategory = Mage::registry('current_category') ?>
<?php if (count($_categories) > 0): ?>
<ul class="category">
<?php foreach($_categories as $_category): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_category) ?>">
<?php echo $_category->getName() ?>
</a>
<?php if ($currentCategory->getId() && $currentCategory->getId() == $_category->getId()): ?>
<?php $_category = Mage::getModel('catalog/category')->load($_category->getId()) ?>
<?php $_subcategories = $_category->getChildrenCategories() ?>
<?php if (count($_subcategories) > 0): ?>
<ul class="subcategory">
<?php foreach($_subcategories as $_subcategory): ?>
<li>
<a href="<?php echo $_helper->getCategoryUrl($_subcategory) ?>">
<?php echo $_subcategory->getName() ?>
</a>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
<?php endif; ?>
</li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
EDIT
<ul class="subcategory">
<? foreach ($_categories as $_category):?>
<? if($_category->getIsActive()):
$cur_subcategory=Mage::getModel('catalog/category')->load($_category->getId());
$layer = Mage::getSingleton('catalog/layer');
$layer->setCurrentCategory($cur_subcategory);
?>
<li> <?php echo $_category->getName()?></li>
<? endif;?>
<?endforeach?>
</ul>
Or you can go throw this Detail documentation, i am sure that would be really helpful to you.
// get current category
$current_category = $layer->getCurrentCategory();
// get sub categories of current category
$parent_categories = Mage::getModel('catalog/category')->getCategories($current_category->getId());
// go through each sub category and get their sub categories.
foreach($parent_categories as $child_category)
{
$child_category_id = $child_category->getId();
$grandchild_categories = Mage::getModel('catalog/category')->getCategories($child_category_id);
}
Here is the tested code for showing sub categories. Just put this code above "Toolbar" code in your custom theme "Magento_catalog/templet/product/list.phtml"
<?php
$objectManager = \Magento\Framework\App\ObjectManager::getInstance();
$category = $objectManager->get('Magento\Framework\Registry')->registry('current_category');//get current category
$subcats = $category->getChildrenCategories();
$_helper = $this->helper('Magento\Catalog\Helper\Output');
$imageHelper = \Magento\Framework\App\ObjectManager::getInstance()->get(\Magento\Catalog\Helper\Image::class);
if(count ($subcats) > 0)
{
?>
<div class = "sub-cat-div">
<ul class = "sub-cat-main">
<?php
foreach ($subcats as $subcat) {
if ($subcat->getIsActive()) {
$_category = $objectManager->create('Magento\Catalog\Model\Category')->load($subcat->getId());
$_outputhelper = $this->helper('Magento\Catalog\Helper\Output');
$subcaturl = $_category->getUrl();
$_imgHtml = '';
if ($_imgUrl = $_category->getImageUrl()) {
$_imgHtml = '<img src="' . $_imgUrl . '" />';
$_imgHtml = $_outputhelper->categoryAttribute($_category, $_imgHtml, 'image');
echo '<li class="sub-cat-image">' . $_imgHtml . '<span style="background-color: rgba(255,255,255,0.9)" class="content bg-white"><strong>' . $_category->getName() . '</strong></span></li>';
}
else{
$_imgUrl = $imageHelper->getDefaultPlaceholderUrl('image');
$_imgHtml = '<img src="' . $_imgUrl . '" />';
$_imgHtml = $_outputhelper->categoryAttribute($_category, $_imgHtml, 'image');
echo '<li class="sub-cat-image">' . $_imgHtml . '<span style="background-color: rgba(255,255,255,0.9)" class="content bg-white"><strong>' . $_category->getName() . '</strong></span></li>';
}
}
} ?>
</ul>
</div>
<?php
}
?>

Alternative layout is applied to an article but not the other

I'm using Joomla 3.x and create an article override. It works fine for some articles. But when I apply to another article, inside a single article menu item, it not work.
UPDATE
Here is my entire override file:
<?php
/**
* #package Joomla.Site
* #subpackage com_content
*
* #copyright Copyright (C) 2005 - 2013 Open Source Matters, Inc. All rights reserved.
* #license GNU General Public License version 2 or later; see LICENSE.txt
*/
defined('_JEXEC') or die;
JHtml::addIncludePath(JPATH_COMPONENT . '/helpers');
// Create shortcuts to some parameters.
$params = $this->item->params;
$images = json_decode($this->item->images);
$urls = json_decode($this->item->urls);
$canEdit = $params->get('access-edit');
$user = JFactory::getUser();
$info = $params->get('info_block_position', 0);
JHtml::_('behavior.caption');
?>
<div class="item-page<?php echo $this->pageclass_sfx?>">
<?php if ($this->params->get('show_page_heading') && $params->get('show_title')) : ?>
<div class="page-header">
<h1> <?php echo $this->escape($this->params->get('page_heading')); ?> </h1>
</div>
<?php endif;
if (!empty($this->item->pagination) && $this->item->pagination && !$this->item->paginationposition && $this->item->paginationrelative)
{
echo $this->item->pagination;
}
?>
<?php if ($params->get('show_title') || $params->get('show_author')) : ?>
<div class="page-header">
<h2>
<?php if ($this->item->state == 0) : ?>
<span class="label label-warning"><?php echo JText::_('JUNPUBLISHED'); ?></span>
<?php endif; ?>
<?php if ($params->get('show_title')) : ?>
<?php if ($params->get('link_titles') && !empty($this->item->readmore_link)) : ?>
<?php echo $this->escape($this->item->title); ?>
<?php else : ?>
<?php echo $this->escape($this->item->title); ?>
<?php endif; ?>
<?php endif; ?>
</h2>
<p class="date-created"><?php echo JText::sprintf('COM_CONTENT_CREATED_DATE_ON', JHtml::_('date', $this->item->created, JText::_('DATE_FORMAT_LC3'))); ?></p>
</div>
<?php endif; ?>
<?php if (!$this->print) : ?>
<?php if ($canEdit || $params->get('show_print_icon') || $params->get('show_email_icon')) : ?>
<div class="btn-group pull-right">
<a class="btn dropdown-toggle" data-toggle="dropdown" href="#"> <span class="icon-cog"></span> <span class="caret"></span> </a>
<?php // Note the actions class is deprecated. Use dropdown-menu instead. ?>
<ul class="dropdown-menu actions">
<?php if ($params->get('show_print_icon')) : ?>
<li class="print-icon"> <?php echo JHtml::_('icon.print_popup', $this->item, $params); ?> </li>
<?php endif; ?>
<?php if ($params->get('show_email_icon')) : ?>
<li class="email-icon"> <?php echo JHtml::_('icon.email', $this->item, $params); ?> </li>
<?php endif; ?>
<?php if ($canEdit) : ?>
<li class="edit-icon"> <?php echo JHtml::_('icon.edit', $this->item, $params); ?> </li>
<?php endif; ?>
</ul>
</div>
<?php endif; ?>
<?php else : ?>
<div class="pull-right">
<?php echo JHtml::_('icon.print_screen', $this->item, $params); ?>
</div>
<?php endif; ?>
<?php $useDefList = ($params->get('show_modify_date') || $params->get('show_publish_date') || $params->get('show_create_date')
|| $params->get('show_hits') || $params->get('show_category') || $params->get('show_parent_category') || $params->get('show_author')); ?>
<?php if ($useDefList && ($info == 0 || $info == 2)) : ?>
<div class="article-info muted">
<dl class="article-info">
<!--<dt class="article-info-term"><?php echo JText::_('COM_CONTENT_ARTICLE_INFO'); ?></dt>-->
<?php if ($params->get('show_author') && !empty($this->item->author )) : ?>
<dd class="createdby">
<?php $author = $this->item->created_by_alias ? $this->item->created_by_alias : $this->item->author; ?>
<?php if (!empty($this->item->contactid) && $params->get('link_author') == true) : ?>
<?php
$needle = 'index.php?option=com_contact&view=contact&id=' . $this->item->contactid;
$menu = JFactory::getApplication()->getMenu();
$item = $menu->getItems('link', $needle, true);
$cntlink = !empty($item) ? $needle . '&Itemid=' . $item->id : $needle;
?>
<?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', JHtml::_('link', JRoute::_($cntlink), $author)); ?>
<?php else: ?>
<?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', $author); ?>
<?php endif; ?>
</dd>
<?php endif; ?>
<?php if ($params->get('show_parent_category') && !empty($this->item->parent_slug)) : ?>
<dd class="parent-category-name">
<?php $title = $this->escape($this->item->parent_title);
$url = ''.$title.'';?>
<?php if ($params->get('link_parent_category') && !empty($this->item->parent_slug)) : ?>
<?php echo JText::sprintf('COM_CONTENT_PARENT', $url); ?>
<?php else : ?>
<?php echo JText::sprintf('COM_CONTENT_PARENT', $title); ?>
<?php endif; ?>
</dd>
<?php endif; ?>
<?php if ($params->get('show_category')) : ?>
<dd class="category-name">
<?php $title = $this->escape($this->item->category_title);
$url = '' . $title . '';?>
<?php if ($params->get('link_category') && $this->item->catslug) : ?>
<?php echo JText::sprintf('COM_CONTENT_CATEGORY', $url); ?>
<?php else : ?>
<?php echo JText::sprintf('COM_CONTENT_CATEGORY', $title); ?>
<?php endif; ?>
</dd>
<?php endif; ?>
<?php if ($params->get('show_publish_date')) : ?>
<dd class="published">
<!--<span class="icon-calendar"></span>--> <?php echo JText::sprintf('COM_CONTENT_PUBLISHED_DATE_ON', JHtml::_('date', $this->item->publish_up, JText::_('DATE_FORMAT_LC3'))); ?>
</dd>
<?php endif; ?>
<?php if ($info == 0) : ?>
<?php if ($params->get('show_modify_date')) : ?>
<dd class="modified">
<!--<span class="icon-calendar"></span>--> <?php echo JText::sprintf('COM_CONTENT_LAST_UPDATED', JHtml::_('date', $this->item->modified, JText::_('DATE_FORMAT_LC3'))); ?>
</dd>
<?php endif; ?>
<?php if ($params->get('show_create_date')) : ?>
<dd class="create">
<!--<span class="icon-calendar"></span>--> <?php echo JText::sprintf('COM_CONTENT_CREATED_DATE_ON', JHtml::_('date', $this->item->created, JText::_('DATE_FORMAT_LC3'))); ?>
</dd>
<?php endif; ?>
<?php if ($params->get('show_hits')) : ?>
<dd class="hits">
<span class="icon-eye-open"></span> <?php echo JText::sprintf('COM_CONTENT_ARTICLE_HITS', $this->item->hits); ?>
</dd>
<?php endif; ?>
<?php endif; ?>
</dl>
</div>
<?php endif; ?>
<?php if (!$params->get('show_intro')) : echo $this->item->event->afterDisplayTitle; endif; ?>
<?php echo $this->item->event->beforeDisplayContent; ?>
<?php if (isset($urls) && ((!empty($urls->urls_position) && ($urls->urls_position == '0')) || ($params->get('urls_position') == '0' && empty($urls->urls_position)))
|| (empty($urls->urls_position) && (!$params->get('urls_position')))) : ?>
<?php echo $this->loadTemplate('links'); ?>
<?php endif; ?>
<?php if ($params->get('access-view')):?>
<?php if (isset($images->image_fulltext) && !empty($images->image_fulltext)) : ?>
<?php $imgfloat = (empty($images->float_fulltext)) ? $params->get('float_fulltext') : $images->float_fulltext; ?>
<div class="pull-<?php echo htmlspecialchars($imgfloat); ?> item-image"> <img
<?php if ($images->image_fulltext_caption):
echo 'class="caption"'.' title="' .htmlspecialchars($images->image_fulltext_caption) . '"';
endif; ?>
src="<?php echo htmlspecialchars($images->image_fulltext); ?>" alt="<?php echo htmlspecialchars($images->image_fulltext_alt); ?>"/> </div>
<?php endif; ?>
<?php
if (!empty($this->item->pagination) && $this->item->pagination && !$this->item->paginationposition && !$this->item->paginationrelative):
echo $this->item->pagination;
endif;
?>
<?php if (isset ($this->item->toc)) :
echo $this->item->toc;
endif; ?>
<div class="article-text"><?php echo $this->item->text; ?></div>
<?php if ($useDefList && ($info == 1 || $info == 2)) : ?>
<div class="article-info muted">
<dl class="article-info">
<!--<dt class="article-info-term"><?php echo JText::_('COM_CONTENT_ARTICLE_INFO'); ?></dt>-->
<?php if ($info == 1) : ?>
<?php if ($params->get('show_author') && !empty($this->item->author )) : ?>
<dd class="createdby">
<?php $author = $this->item->created_by_alias ? $this->item->created_by_alias : $this->item->author; ?>
<?php if (!empty($this->item->contactid) && $params->get('link_author') == true) : ?>
<?php
$needle = 'index.php?option=com_contact&view=contact&id=' . $this->item->contactid;
$menu = JFactory::getApplication()->getMenu();
$item = $menu->getItems('link', $needle, true);
$cntlink = !empty($item) ? $needle . '&Itemid=' . $item->id : $needle;
?>
<?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', JHtml::_('link', JRoute::_($cntlink), $author)); ?>
<?php else: ?>
<?php echo JText::sprintf('COM_CONTENT_WRITTEN_BY', $author); ?>
<?php endif; ?>
</dd>
<?php endif; ?>
<?php if ($params->get('show_parent_category') && !empty($this->item->parent_slug)) : ?>
<dd class="parent-category-name">
<?php $title = $this->escape($this->item->parent_title);
$url = '' . $title . '';?>
<?php if ($params->get('link_parent_category') && $this->item->parent_slug) : ?>
<?php echo JText::sprintf('COM_CONTENT_PARENT', $url); ?>
<?php else : ?>
<?php echo JText::sprintf('COM_CONTENT_PARENT', $title); ?>
<?php endif; ?>
</dd>
<?php endif; ?>
<?php if ($params->get('show_category')) : ?>
<dd class="category-name">
<?php $title = $this->escape($this->item->category_title);
$url = '' . $title . '';?>
<?php if ($params->get('link_category') && $this->item->catslug) : ?>
<?php echo JText::sprintf('COM_CONTENT_CATEGORY', $url); ?>
<?php else : ?>
<?php echo JText::sprintf('COM_CONTENT_CATEGORY', $title); ?>
<?php endif; ?>
</dd>
<?php endif; ?>
<?php if ($params->get('show_publish_date')) : ?>
<dd class="published">
<!--<!--<span class="icon-calendar"></span>-->-->
<?php echo JText::sprintf('COM_CONTENT_PUBLISHED_DATE_ON', JHtml::_('date', $this->item->publish_up, JText::_('DATE_FORMAT_LC3'))); ?>
</dd>
<?php endif; ?>
<?php endif; ?>
<?php if ($params->get('show_create_date')) : ?>
<dd class="create">
<!--<!--<span class="icon-calendar"></span>-->-->
<?php echo JText::sprintf('COM_CONTENT_CREATED_DATE_ON', JHtml::_('date', $this->item->modified, JText::_('DATE_FORMAT_LC3'))); ?>
</dd>
<?php endif; ?>
<?php if ($params->get('show_modify_date')) : ?>
<dd class="modified">
<!--<span class="icon-calendar"></span>-->
<?php echo JText::sprintf('COM_CONTENT_LAST_UPDATED', JHtml::_('date', $this->item->modified, JText::_('DATE_FORMAT_LC3'))); ?>
</dd>
<?php endif; ?>
<?php if ($params->get('show_hits')) : ?>
<dd class="hits">
<span class="icon-eye-open"></span> <?php echo JText::sprintf('COM_CONTENT_ARTICLE_HITS', $this->item->hits); ?>
</dd>
<?php endif; ?>
</dl>
</div>
<?php endif; ?>
<?php
if (!empty($this->item->pagination) && $this->item->pagination && $this->item->paginationposition && !$this->item->paginationrelative):
echo $this->item->pagination;
?>
<?php endif; ?>
<?php if (isset($urls) && ((!empty($urls->urls_position) && ($urls->urls_position == '1')) || ($params->get('urls_position') == '1'))) : ?>
<?php echo $this->loadTemplate('links'); ?>
<?php endif; ?>
<?php //optional teaser intro text for guests ?>
<?php elseif ($params->get('show_noauth') == true && $user->get('guest')) : ?>
<?php echo $this->item->introtext; ?>
<?php //Optional link to let them register to see the whole article. ?>
<?php if ($params->get('show_readmore') && $this->item->fulltext != null) :
$link1 = JRoute::_('index.php?option=com_users&view=login');
$link = new JURI($link1);?>
<p class="readmore">
<a href="<?php echo $link; ?>">
<?php $attribs = json_decode($this->item->attribs); ?>
<?php
if ($attribs->alternative_readmore == null) :
echo JText::_('COM_CONTENT_REGISTER_TO_READ_MORE');
elseif ($readmore = $this->item->alternative_readmore) :
echo $readmore;
if ($params->get('show_readmore_title', 0) != 0) :
echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
endif;
elseif ($params->get('show_readmore_title', 0) == 0) :
echo JText::sprintf('COM_CONTENT_READ_MORE_TITLE');
else :
echo JText::_('COM_CONTENT_READ_MORE');
echo JHtml::_('string.truncate', ($this->item->title), $params->get('readmore_limit'));
endif; ?>
</a>
</p>
<?php endif; ?>
<?php endif; ?>
<?php
if (!empty($this->item->pagination) && $this->item->pagination && $this->item->paginationposition && $this->item->paginationrelative) :
echo $this->item->pagination;
?>
<?php endif; ?>
<?php echo $this->item->event->afterDisplayContent; ?> </div>
UPDATE 2
I discovered one thing: if the article is associated with a menu item (type:Category List), the Alternative Layout works. But when the article is associated a menu item (type:Single Article), the Alternative Layout does not work. How do the Alternative Layout function in both cases?
SOLVED!
I Create a custom menu item type.
More informations here: http://docs.joomla.org/Layout_Overrides_in_Joomla_2.5
And here: http://jure-stern.si/blog/custom-menu-item-types-in-joomla-with-xml-files/

Resources