【问题标题】:Magento CMS pages menuMagento CMS 页面菜单
【发布时间】:2011-01-18 06:58:14
【问题描述】:

我稍微修改了Magento static pages menu 的代码,以包含一个用于活动菜单链接的类。

<div>
<?php $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());?>
<?php  $collection->getSelect()
      ->where('is_active = 1'); ?>
<ul id="nav-top-list">
<?php foreach ($collection as $page): ?>
  <?php $PageData = $page->getData(); ?>
  <?php if($PageData['menu']!= 'false') { ?>
  <li>
    <a href="/<?php echo $PageData['identifier']?>"<?php if ($url == "/".$PageData['identifier']) { ?>class="active"<?php } ?>><?php echo $PageData['title'] ?></a>
  </li>
  <?php } ?>
<?php endforeach; ?>

我已经向 CMS 页面添加了一个新字段,以使用 true 或 false 指定页面是否应包含在菜单中。实际上,正如您在上面看到的,我只检查设置是否为 false,其他所有内容都会获得链接。如果要使用它,则需要向 cms_page 表添加一个新字段。

        $fieldset->addField('menu', 'text', array(
        'name'      => 'menu',
        'label'     => Mage::helper('cms')->__('On Menu'),
        'title'     => Mage::helper('cms')->__('On Menu'),
        'required'  => true,
        'disabled'  => $isElementDisabled
    ));

我还在 CMS 页面中添加了另一个名为 sortorder 的字段,其中包含一个数字,用于表示链接在菜单上的顺序。有人对我如何使用新的 sortorder 字段对菜单链接的顺序进行排序有任何提示吗?

干杯

【问题讨论】:

    标签: php magento menu


    【解决方案1】:

    @安迪·弗兰

    ('sortorder') 触发 sql 错误。

    搭配

    效果更好
    $collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(
        Mage::app()->getStore()->getId())->setOrder('**sort_order**', 'asc');
    

    【讨论】:

      【解决方案2】:

      你试过类似的东西吗?:

      $collection=Mage::getModel('cms/page')->getCollection()->addStoreFilter(
          Mage::app()->getStore()->getId())->setOrder('sortorder', 'asc');
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2013-08-22
        • 2010-11-16
        • 1970-01-01
        • 2012-04-22
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2011-06-28
        相关资源
        最近更新 更多