Magento static pages menu

14,866

Solution 1

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 found in /lib/Zend/Db/Select.php(FYI)

Solution 2

To exclude more than just the no-route I added a new field to the CMS pages to specify if the page should have a menu item or not using true or false. I followed Add a new CMS Field and used the following in main.php

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

Then changed this line:

<?php if($PageData['identifier']!='no-route') { ?>

to

<?php if($PageData['menu']!= 'false') { ?>

Solution 3

Here is another way to put static links to Magento catalog menu.

First, create static page, assign some url key to it, for example, "my-test-page".

Go to /app/code/core/Mage/Catalog/Block, copy file Navigation.php to /app/code/local/Mage/Catalog/Block, now you able to edit it without any worries about the possibility of loosing your changes with Magento upgrade.

Open file Navigation.php at line 265 (magento 1.4) function _renderCategoryMenuItemHtml(...), change code:

    $htmlLi .= '>';
    $html[] = $htmlLi;                    

    $html[] = '<a href="'.$this->getCategoryUrl($category).'"'.$linkClass.'>';
    $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
    $html[] = '</a>';

to that:

    $htmlLi .= '>';
    $html[] = $htmlLi;        

    if(preg_match('/\/static-/', $this->getCategoryUrl($category))) {
        $link_url = str_replace("static-", "", $this->getCategoryUrl($category));            
    } else {
        $link_url = $this->getCategoryUrl($category);            
    }

    $html[] = '<a href="'.$link_url.'"'.$linkClass.'>';
    $html[] = '<span>' . $this->escapeHtml($category->getName()) . '</span>';
    $html[] = '</a>';

Now go to Categories management, edit category, change URL key to that: "static-my-test-page" and uncheck "Create Permanent Redirect for old URL" check-box. After saving category you will have link to my-test-page at top categories menu in Magento.

So after all that changes you can convert category link to static page link by adding prefix "static-" to category URL key.

Share:
14,866
Admin
Author by

Admin

Updated on June 04, 2022

Comments

  • Admin
    Admin almost 2 years

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

    • 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?