Reputation: 21
I have modified the code from Magento static pages menu a little bit to include a class for the active menu link.
<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; ?>
And I have added a new field to the CMS pages to specify if the page should be included in the menu by using true or false. Actually, as you can see above I am only checking for a setting of false, everything else will get a link. You'll need to add a new field to the cms_page table if you are going to use this.
$fieldset->addField('menu', 'text', array(
'name' => 'menu',
'label' => Mage::helper('cms')->__('On Menu'),
'title' => Mage::helper('cms')->__('On Menu'),
'required' => true,
'disabled' => $isElementDisabled
));
I have also added another field to the CMS pages named sortorder which contains a number for the order the links should be on the menu. Has anybody got any tips on how I could use the new sortorder field to sort the order of the menu links?
Cheers
Upvotes: 1
Views: 4250
Reputation: 11
Have you tried something like?:
$collection=Mage::getModel('cms/page')->getCollection()->addStoreFilter(
Mage::app()->getStore()->getId())->setOrder('sortorder', 'asc');
Upvotes: 0
Reputation: 11
@Andy Flan
the ('sortorder') triggers a sql error.
Works better with
$collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(
Mage::app()->getStore()->getId())->setOrder('**sort_order**', 'asc');
Upvotes: 1