【问题标题】:Magento get CMS pages based on layoutMagento 根据布局获取 CMS 页面
【发布时间】:2014-08-20 20:53:47
【问题描述】:

所以我正在构建一个自定义面包屑导航来列出所有筹款选项。这些页面使用了一个独特的布局,称为"fundraising_page." 有没有办法只在它们有"fundraising_page" layout? 的情况下抓取页面到目前为止我有这个,它抓取每个页面,而不管它使用的是什么模板。

所以我只需要列出使用"fundraising_page" 模板的页面。

<?php $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());?>
<?php $collection->getSelect()->where('is_active = 1'); ?>
<ul>
<?php foreach ($collection as $page): ?>
<?php $PageData = $page->getData(); ?>
<?php if($PageData['identifier']!='no-route'){ ?>
<li>
<a href="/<?php echo $PageData['identifier']?>"><?php echo $PageData['title'] ?></a>
</li>
<?php } ?>
<?php endforeach; ?>

【问题讨论】:

    标签: php magento magento-1.9.1


    【解决方案1】:

    这里有一些格式良好的代码并使用了正确的方法。

    <?php
    $collection = Mage::getModel('cms/page')->getCollection()
        ->addStoreFilter(Mage::app()->getStore()->getId())
        ->addFieldToFilter('is_active', 1)
        ->addFieldToFilter('root_template', 'fundraising_page');
    ?>
    <?php foreach ($collection as $page): ?>
        <?php if ($page->getIdentifier() != 'no-route'): ?>
            <li>
              <a href="<?php echo Mage::getUrl($page->getIdentifier())?>"><?php echo $page->getTitle() ?></a>
            </li>
        <?php endif; ?>
    <?php endforeach; ?>
    

    【讨论】:

    • 谢谢伙计,工作就像一个魅力!有什么办法可以过滤掉当前页面?因此,如果您使用筹款选项 1,则筹款选项 1 不会显示在菜单中?
    • 使用Mage::getSingleton('cms/page')-&gt;getIdentifier() - 它返回当前的CMS页面标识符。
    【解决方案2】:

    代替if($PageData['identifier']!='no-route')试试

    if($PageData['root_template']=='fundraising_page')
    

    【讨论】:

    • 谢谢,我明天试试。
    猜你喜欢
    • 2013-09-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-01-24
    • 2012-12-11
    相关资源
    最近更新 更多