Magento隐藏了来宾的导航菜单项

时间:2012-10-03 16:11:31

标签: magento navigation hide

我正在magento社区版1.7上运行magento自定义模板。如何隐藏来自客人的$ custom_tab3?我希望该选项卡仅显示登录用户。请参阅下面的代码。任何帮助都非常赞赏!

 <ul id="nav">
    <?php if (Mage::getStoreConfig('celebritysettings/celebritysettings_header/navigation_home')): ?>
     <li class="level0 level-top">
        <a href="<?php echo $this->getBaseUrl(); ?>how-it-works"><span><?php echo $this->__('How It Works'); ?></span></a>
     </li>
 <?php endif; ?>
    <?php
    echo $_menu;
    $custom_tab = Mage::getModel('cms/block')->load('celebrity_navigation_block');
    if($custom_tab->getIsActive()) {
        echo '
        <li class="level0 level-top parent custom-block">
            <a href="'.$this->getBaseUrl().'gift" class="level-top">
                <span>'.$custom_tab->getTitle().'</span>
            </a>
            <div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block')->toHtml().'</div>
        </li>';
    }

    $custom_tab2 = Mage::getModel('cms/block')->load('celebrity_navigation_block2');
    if($custom_tab2->getIsActive()) {
        echo '
        <li class="level0 level-top parent custom-block" >
            <a href="'.$this->getBaseUrl().'plans" class="level-top">
                <span>'.$custom_tab2->getTitle().'</span>
            </a>
            <div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block2')->toHtml().'</div>
        </li>';
    }


    $custom_tab3 = Mage::getModel('cms/block')->load('celebrity_navigation_block3');
    if($custom_tab3->getIsActive()) {
        echo '
        <li class="level0 level-top parent custom-block">
            <a href="'.$this->getBaseUrl().'showroom" class="level-top">
                <span>'.$custom_tab3->getTitle().'</span>
            </a>
            <div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block3')->toHtml().'</div>
        </li>';
    }


    $custom_tab4 = Mage::getModel('cms/block')->load('celebrity_navigation_block4');
    if($custom_tab4->getIsActive()) {
        echo '
        <li class="level0 level-top parent custom-block">
            <a href="'.$this->getBaseUrl().'magazine" class="level-top">
                <span>'.$custom_tab4->getTitle().'</span>
            </a>
            <div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block4')->toHtml().'</div>
        </li>';
    }

    ?>
</ul>

1 个答案:

答案 0 :(得分:0)

您可以使用Mage::getSingleton('customer/session')->isLoggedIn()检查当前用户是否已登录。在您的代码中,您可以像这样使用它:

$custom_tab3 = Mage::getModel('cms/block')->load('celebrity_navigation_block3');
if($custom_tab3->getIsActive() && Mage::getSingleton('customer/session')->isLoggedIn()) {
    echo '
    <li class="level0 level-top parent custom-block">
        <a href="'.$this->getBaseUrl().'showroom" class="level-top">
            <span>'.$custom_tab3->getTitle().'</span>
        </a>
        <div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block3')->toHtml().'</div>
    </li>';
}

甚至

if(Mage::getSingleton('customer/session')->isLoggedIn()) {
    $custom_tab3 = Mage::getModel('cms/block')->load('celebrity_navigation_block3');
    if($custom_tab3->getIsActive()) {
        echo '
        <li class="level0 level-top parent custom-block">
            <a href="'.$this->getBaseUrl().'showroom" class="level-top">
                <span>'.$custom_tab3->getTitle().'</span>
            </a>
            <div class="sub-wrapper">'.$this->getLayout()->createBlock('cms/block')->setBlockId('celebrity_navigation_block3')->toHtml().'</div>
        </li>';
    }
}

以防止不必要地检索cms/block模型。