我在Magento中遇到导航问题。子类别以有趣的方式显示,我也不想要它们。请参阅以下屏幕截图:
http://tinypic.com/r/2l97byp/8
在左上角,菜单中显示了孩子。但是我不希望他们扩展到一个新的区块,而只是显示在他们的parrent类别下面,如图所示:
tinypic.com/r/16l0kk3/8
我有两组代码,但是我不知道要编辑什么来获得所需的结果。我试图让它发挥作用,但没有运气。
两个代码部分:
top.phtml:
<?php
/**
* Top menu for store
*
* @see Olegnax_Navigation_Block_Navigation
*/
?>
<?php
/**
* $this->renderCategoriesMenuHtml() supports optional arguments:
* int Level number for list item class to start from
* string Extra class of outermost list items
* string If specified wraps children list in div with this class
*/
?>
<!-- navigation BOF -->
<?php $_menu = $this->renderCategoriesMenuHtml(0, 'level-top', 'sub-wrapper' ) ?>
<?php if($_menu): ?>
<nav class="olegnax">
<ul id="nav">
<?php if (Mage::getStoreConfig('celebritysettings/celebritysettings_header/navigation_home')): ?>
<li class="level0 level-top">
<a href="<?php echo $this->getBaseUrl(); ?>"><span><?php echo $this->__('Home'); ?></span></a>
</li>
<?php endif; ?>
<?php
echo $_menu;
$custom_tab = Mage::getModel('cms/block')->load('celebrity_navigation_block');
if($custom_tab->getIsActive()) {
echo '
<li class="level0 level-top parent custom-block">
<a href="#" class="level-top">
<span>'.$custom_tab->getTitle().'</span>
</a>
<div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block')->toHtml().'</div>
</li>';
}
?>
</ul>
</nav>
<?php endif ?>
<!-- navigation EOF -->
和Navigation.phtml:
<?php
/**
* @version 1.0 12.0.2012
* @author Olegnax http://www.olegnax.com <mail@olegnax.com>
* @copyright Copyright (C) 2010 - 2012 Olegnax
*/
class Olegnax_Navigation_Block_Navigation extends Mage_Catalog_Block_Navigation
{
/**
* columns html
*
* @var array
*/
protected $_columnHtml;
/**
* Render category to html
*
* @param Mage_Catalog_Model_Category $category
* @param int Nesting level number
* @param boolean Whether ot not this item is last, affects list item class
* @param boolean Whether ot not this item is first, affects list item class
* @param boolean Whether ot not this item is outermost, affects list item class
* @param string Extra class of outermost list items
* @param string If specified wraps children list in div with this class
* @param boolean Whether ot not to add on* attributes to list item
* @return string
*/
protected function _renderCategoryMenuItemHtml($category, $level = 0, $isLast = false, $isFirst = false,
$isOutermost = false, $outermostItemClass = '', $childrenWrapClass = '', $noEventAttributes = false)
{
if (!$category->getIsActive()) {
return '';
}
$html = array();
// get all children
if (Mage::helper('catalog/category_flat')->isEnabled()) {
$children = (array)$category->getChildrenNodes();
$childrenCount = count($children);
} else {
$children = $category->getChildren();
$childrenCount = $children->count();
}
$hasChildren = ($children && $childrenCount);
// select active children
$activeChildren = array();
foreach ($children as $child) {
if ($child->getIsActive()) {
$activeChildren[] = $child;
}
}
$activeChildrenCount = count($activeChildren);
$hasActiveChildren = ($activeChildrenCount > 0);
// prepare list item html classes
$classes = array();
$classes[] = 'level' . $level;
$classes[] = 'nav-' . $this->_getItemPosition($level);
if ($this->isCategoryActive($category)) {
$classes[] = 'active';
}
$linkClass = '';
if ($isOutermost && $outermostItemClass) {
$classes[] = $outermostItemClass;
$linkClass = ' class="'.$outermostItemClass.'"';
}
if ($isFirst) {
$classes[] = 'first';
}
if ($isLast) {
$classes[] = 'last';
}
if ($hasActiveChildren) {
$classes[] = 'parent';
}
// prepare list item attributes
$attributes = array();
if (count($classes) > 0) {
$attributes['class'] = implode(' ', $classes);
}
if ($hasActiveChildren && !$noEventAttributes) {
$attributes['onmouseover'] = 'toggleMenu(this,1)';
$attributes['onmouseout'] = 'toggleMenu(this,0)';
}
// assemble list item with attributes
$htmlLi = '<li';
foreach ($attributes as $attrName => $attrValue) {
$htmlLi .= ' ' . $attrName . '="' . str_replace('"', '\"', $attrValue) . '"';
}
$htmlLi .= '>';
$html[] = $htmlLi;
$html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
$html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
$html[] = '</a>';
if ( $level == 0 ) {
//get category description
$ca = Mage::getModel('catalog/category')->load($category->getId());
$description = $ca->getDescription();
if ( empty($description) || !Mage::getStoreConfig('celebritysettings/celebritysettings_navigation/show_description') ) {
$columns = 4;
} else {
$columns = 2;
}
$columnItemsNum = array_fill(0, $columns, floor($activeChildrenCount / $columns));
if ( $activeChildrenCount % $columns > 0 ) {
for ($i = 0; $i < ($activeChildrenCount % $columns); $i++ ) {
$columnItemsNum[$i]++;
}
}
$this->_columnHtml = array();
}
// render children
$htmlChildren = '';
$j = 0; //child index
$i = 0; //column index
$itemsCount = $columnItemsNum[$i];
foreach ($activeChildren as $child) {
if ( $level == 0 ) {
$isLast = (($j+1) == $itemsCount || $j == $activeChildrenCount - 1);
if ( $isLast ) {
$i++;
$itemsCount += $columnItemsNum[$i];
}
} else {
$isLast = ($j == $activeChildrenCount - 1);
}
$childHtml = $this->_renderCategoryMenuItemHtml(
$child,
($level + 1),
$isLast,
($j == 0),
false,
$outermostItemClass,
$childrenWrapClass,
$noEventAttributes
);
if ( $level == 0 ) {
$this->_columnHtml[] = $childHtml;
} else {
$htmlChildren .= $childHtml;
}
$j++;
}
if ( $level == 0 && $this->_columnHtml ) {
$i = 0;
foreach ( $columnItemsNum as $columnNum ) {
$chunk = array_slice($this->_columnHtml, $i, $columnNum);
$i += $columnNum;
$htmlChildren .= '<li '.(count($this->_columnHtml) == $i ? 'class="last"' : '').'><ol>';
foreach ( $chunk as $item ) {
$htmlChildren .= $item;
}
$htmlChildren .= '</ol></li>';
}
}
if ( !empty($description) && !empty($htmlChildren) && Mage::getStoreConfig('celebritysettings/celebritysettings_navigation/show_description') ) {
$htmlChildren .= '<li class="menu-category-description clearfix">'.$description;
if ( Mage::getStoreConfig('celebritysettings/celebritysettings_navigation/show_learn_more') ) {
$htmlChildren .= '<p><button class="button" onclick="window.location=\''.$this->getCategoryUrl($category).'\'"><span><span>'.$this->__('learn more').'</span></span></button></p>';
}
$htmlChildren .= '</li>';
}
if (!empty($htmlChildren)) {
if ($childrenWrapClass) {
$html[] = '<div class="' . $childrenWrapClass . '">';
}
$html[] = '<ul class="level' . $level . '">';
$html[] = $htmlChildren;
$html[] = '</ul>';
if ($childrenWrapClass) {
$html[] = '</div>';
}
}
$html[] = '</li>';
$html = implode("\n", $html);
return $html;
} }
我希望有人能看到该做什么才能对图像产生影响:)
最诚挚的问候, 帕特里克
答案 0 :(得分:0)
好吧,Alan Storm是正确的但是为了它的价值,回答你的问题'我编辑哪个文件',你编辑的文件是Navigation.php。我这样说是因为top.phtml有一行echo $_menu;
。无论如何,protected function _renderCategoryMenuItemHtml()
中的代码可能有点令人费解,当我阅读代码并思考你想要实现的目标时,我认为你应该:
a)尝试评论一下:
if ($hasActiveChildren && !$noEventAttributes) {
$attributes['onmouseover'] = 'toggleMenu(this,1)';
$attributes['onmouseout'] = 'toggleMenu(this,0)';
}
为了删除鼠标悬停交互,然后看看你是否可以破解CSS以获得你想要的布局
或
b)丢弃protected function _renderCategoryMenuItemHtml()
中的所有代码并重新开始:重写它以使用现有代码的元素显示所需的HTML结构。