如何在活动类中添加顶部链接

时间:2015-04-17 10:18:00

标签: magento

如何在热门链接中添加有效类。

  

\应用\设计\前端\默认\默认\模板\页面\模板\ links.phtml

<?php $_links = $this->getLinks(); ?>
<?php if (count($_links) > 0): ?>
    <ul class="links"<?php if ($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif; ?>>
        <?php foreach ($_links as $_link): ?>
            <?php if ($_link instanceof Mage_Core_Block_Abstract): ?>
                <?php echo $_link->toHtml() ?>
            <?php else: ?>
                <li<?php if ($_link->getIsFirst() || $_link->getIsLast()): ?> class="<?php if ($_link->getIsFirst()): ?>first<?php endif; ?><?php if ($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
                <?php endif; ?>
            <?php endforeach; ?>
    </ul>
<?php endif; ?>

2 个答案:

答案 0 :(得分:0)

试试这个,它应该有效:

<?php $_links = $this->getLinks(); ?>
<?php 
// active states
// using $_link->getBeforeText() against the RouteName or Idenifier ti get active states
$routeName = Mage::app()->getRequest()->getRouteName();
$identifier = Mage::getSingleton('cms/page')->getIdentifier();
if ($identifier ==null): 
$identifier = $routeName; 
endif;
?>
<?php if(count($_links)>0): ?>
<ul class="links"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
    <?php foreach($_links as $_link): ?>
        <?php if ($_link instanceof Mage_Core_Block_Abstract):?>
            <?php echo $_link->toHtml() ?>
        <?php else: ?>
            <li class="<?php echo $_link->getBeforeText(); if( $identifier == $_link->getBeforeText()): echo " active"; endif; ?> <?php if($_link->getIsFirst()||$_link->getIsLast()): ?><?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?><?php endif; ?>" <?php echo $_link->getLiParams() ?>><?php // echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a><?php echo $_link->getAfterText() ?></li>
        <?php endif;?>
    <?php endforeach; ?>
</ul>

<?php endif; ?>

答案 1 :(得分:0)

    <?php $_links = $this->getLinks(); ?>
<?php if(count($_links)>0): ?>
    <div class="links">
        <?php if($this->getTitle()): ?>
            <div class="block-title"><strong><span><?php echo $this->__($this->getTitle()); ?></span></strong></div>
        <?php endif; ?>
        <ul<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
            <?php foreach($_links as $_link): ?>
                <?php if ($_link instanceof Mage_Core_Block_Abstract):?>
                    <?php echo $_link->toHtml() ?>
                <?php else: ?>
                    <li<?php if($_link->getIsFirst()||$_link->getIsLast()||(Mage::helper('core/url')->getCurrentUrl() == $_link->getUrl())): ?> class="<?php if(Mage::helper('core/url')->getCurrentUrl() == $_link->getUrl()): ?>active <?php endif; ?><?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?>last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>>
                        <?php echo $_link->getBeforeText() ?>
                        <a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?>
                        </a><?php echo $_link->getAfterText() ?></li>
                <?php endif;?>
            <?php endforeach; ?>
        </ul>
    </div>
<?php endif; ?>