2011-03-02 107 views
1

我最近開始在magento工作,而我的老闆給了我在左欄中顯示類別的任務。我有一個靜態HTML文件,我將其粘貼到.phtml文件中,並從xml塊中調用它,並在左列中顯示靜態內容。在magento的左欄顯示類別

我希望它們是動態的,以便可以從後端添加或刪除類別。 我擁有的html格式是表格格式,我想將php代碼插入到相同的html中,以便設計不受干擾,並且變得動態。

回答

2

這可能是你在找什麼:

<?php if (!Mage::registry('current_category')) return ?> 
<?php $_categories = $this->getCurrentChildCategories() ?> 
<?php $_count = is_array($_categories)?count($_categories):$_categories->count(); ?> 
<?php if($_count): ?> 
<div class="block block-layered-nav"> 
    <div class="block-title"> 
     <strong><span><?php echo $this->__('Browse By') ?></span></strong> 
    </div> 
    <div class="block-content"> 
     <dl id="narrow-by-list2"> 
      <dt><?php echo $this->__('Category') ?></dt> 
      <dd> 
       <ol> 
       <?php foreach ($_categories as $_category): ?> 
        <?php if($_category->getIsActive()): ?> 
        <li> 
         <a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="current"<?php endif; ?>><?php echo $this->htmlEscape($_category->getName()) ?></a> (<?php echo $_category->getProductCount() ?>) 
        </li> 
        <?php endif; ?> 
       <?php endforeach ?> 
       </ol> 
      </dd> 
     </dl> 
     <script type="text/javascript">decorateDataList('narrow-by-list2')</script> 
    </div> 
</div> 
<?php endif; ?> 

我在這裏用它:http://marblesthebrainstore.com