2015-04-17 61 views
1

如何添加活動類頂級鏈接。如何添加頂級鏈接在活動類

\程序\設計\前臺\ DEFAULT \ DEFAULT \模板\網頁\模板\ 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; ?> 

回答

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; ?> 
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; ?>