2016-06-09 80 views

回答

1

我找到了解决办法。我们可以按类别确定当前类别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";} ?>"> 
      <a href="<?php echo $_category->getUrl(); ?>" title="<?php echo $_category->getName() ?>"><?php echo $_category->getName() ?></a> 
       <?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";} ?>"> 
        <a href="<?php echo $_subcategory->getUrl(); ?>" title="<?php echo $_subcategory->getName(); ?>"><?php echo $_subcategory->getName(); ?></a> 
        <?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> 
1

(我)首先从管理面板创建自定义类别
(II)然后传递getCategories类别ID()函数的代码

试试这个代码,它适用于我。我希望这项工作适合你。

<?php 
 
$children = Mage::getModel('catalog/category')->getCategories(2); 
 
?> 
 
<div class="menusecond"> 
 
<ul id="second menu"> 
 
<?php 
 
foreach ($children as $category) { ?> 
 
    <li class="mymenu"> 
 
\t 
 
\t <?php $catId = $category->getId(); ?> 
 
\t <?php $cat = Mage::getModel('catalog/category')->load($catId); ?> 
 
\t <a href="<?php echo $cat->getUrl(); ?>"> 
 
\t <?php echo $cat->getName(); ?> 
 
\t </a> 
 
\t </li> 
 
\t 
 
\t 
 
<?php 
 
     
 
} 
 

 
?> 
 
</ul> 
 
</div>

+0

找不到激活或停用类。 –

1

转到app/design/frontend/rwd/default/template/page/html并打开topmenu.phtml文件。发现这个代码<?php if($_menu): ?> <nav id="nav"> <ol class="nav-primary"> <?php echo $_menu ?> </ol> </nav> <?php endif ?>

这个代码将输出你的类别在顶部菜单的形式,如果你不使用任何类型隐藏此代码或其他事情之前或此代码后粘贴此代码。

<ul> <li><a href="<?php echo Mage::getBaseUrl(); ?>">HOME</a></li> <li><a href="<?php echo Mage::getBaseUrl(); ?>aboutus">ABOUT US</a></li> <li><a href="<?php echo Mage::getBaseUrl(); ?>your_page_uri">your_page_name</a></li> <li><a href="<?php echo Mage::getBaseUrl(); ?>your_page_uri">your_page_name</a></li> </ul>