views:

2467

answers:

5

I want to make a menu that will dynamically show the active static pages from CMS; for example if in my CMS i have:

  • About Us (enabled)
  • Shipping & Refund (disabled)
  • Terms and Conditions (enabled)
  • Contacts (enabled)

then the menu would look like:

About US | Terms and Conditions | Contacts

i need just a few tips on how to get started; maybe somebody has already done this before many tahnks!

+1  A: 

In your page/html block create a method containing:

$collection = Mage::getModel('cms/page')->getCollection()->addStoreFilter(Mage::app()->getStore()->getId());
$collection->getSelect()
    ->where('is_active = 1')
    ->order('main_table.sort_order ASC');
return $collection;

Which you can call in your template and foreach() through creating your LIs

Might need some tweaking mind, depending on your setup.

From memory though i think this is built in, have a look in design/frontend/../../templates/page/ i seem to remember striping out some similar functionality in one of the phtml files in there.

where, order and other select stuff can be forund in /lib/Zend/Db/Select.php FYI

Question Mark
A: 

the first answer is not so clear. can you explain it a bit better? i think it's exactly what i need. thanks

+2  A: 

Dougle thanks a lot, that was really helpful!

Fede in magento CMS you can make static pages that you can only acces using its IDENTIFIER; what i wanted is somehow make a menu that will automaticaly display the ACTIVE (enabled) static pages; and if you set status to Disablet it should not be in the menu;

here is the code i used, note there is IF $PageData['identifier']!='no-route'; no-rute is the 404 page, so i don't need it in the menu, but it must be enabled so magento redirects 404 errors to this page;

<div>
    <?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; ?>
</div>
Nice that is what i envisaged, good catch on the no-route, to get the $collection = Mage.... crap out of the view, you can put it in a function in the block. and call $this->getNavLinks();
Question Mark
A: 

Thanks a Lot for all of you !!! You really saved my development hours ....

jerome
A: 

Is there anyway to exclude more then just the no-route (404) page. What I'm looking to achieve is exclude the no-route page and other pages which still need to be enabled but not displayed in my CMS page menu? Any ideas would be greatly appreciated!

Sahus Pilwal