Magento自定义链接获得活动集

时间:2012-02-01 07:17:48

标签: magento url foreach

您好我正在尝试为我的magento网站获取foreach循环的活动状态。 我已经尝试了一切,但它不会工作..这是我的代码:

ksort($catArr);


foreach($catArr as $postion=>$catId){
$_category = Mage::getModel("catalog/category")->load($catId);
?>
<?php
if($_category->getIsActive() )
{
$caturl = $_category->getURL();
$catname = $_category->getName();
?>

<?php if($_category->getdata('left_menu')): ?>

<a  href="<?php echo "$caturl" ?>" > <li class="leftnav" ><div class="nav-name">
<?php echo $catname ?></div></li></a>
<?php endif ?>
<?php 
}
?>
<?php 
}
?>
</ul>
</div>
<?php endif ?>

2 个答案:

答案 0 :(得分:0)

希望您想检查类别是否有效。如果是这样,如果is_active在集合中,则以下代码行可能对您有所帮助。

$_category->getData('is_active') 

如果要将其添加到集合中,请使用

addFieldToSelect('is_Active')

答案 1 :(得分:0)

/*to get current category ID*/
$category_nav_obj = new Mage_Catalog_Block_Navigation();
$current_category= $category_nav_obj->getCurrentCategory();
$current_category_id = $current_category->getId();

/*Then loop as per your code*/

foreach(....):

if($category->getId()==$current_category_id):
  /*do whatever you want to highlight the category*/
endforeach;