Magento Static Pages Menu

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

  • About us (included)
  • Shipping and Returns (Disabled)
  • Terms and conditions (included)
  • Contact (included)

then the menu will look like this:

About USA | Terms of use | Contacts

I need just a few tips on how to get started; maybe someone has already done this before?

+4
source share
4 answers

Dougle thanks a lot that was really helpful!

Fedya in Magento CMS you can create static pages that can only be accessed using IDENTIFIER; I wanted to somehow create a menu that automatically displays static ACTIVE (enabled) pages; and if you set the status to "Disable", it should not be in the menu;

here is the code i used, note that IF $PageData['identifier']!='no-route'; no-rute is a 404 page, so I don’t need a menu, but it needs to 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> 
+5
source

In the 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; 

What you can call in your template and foreach() by creating your LI

Depending on your setting, a certain attitude may be required.

From memory, although I think this is built-in, look at design/frontend/../../templates/page/ , I seem to remember how we would separate some of the similar functions in one of the phtml files.

where, order and other selection items can be found in /lib/Zend/Db/Select.php (FYI)

+1
source

To exclude more than just a route, I added a new field to the CMS pages to indicate whether the page should have a menu item or not use 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 this line changed:

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

to

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

Here is another way to put static links in the Magento directory menu.

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

Go to / app / code / core / Mage / Catalog / Block, copy the Navigation.php file to / app / code / local / Mage / Catalog / Block, now you can edit it without fear of the possibility of losing your changes with the Magento update.

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

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

:

  $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 Category Management, change the category, change the URL to this: "static-my-test-page" and uncheck "Create a permanent redirect for the old URL". After saving the category, you will have a link to my test page in the main categories menu in Magento.

So, after all the changes, you can convert the category link into a static link to the page by adding the prefix β€œstatic-” to the category URL.

+1
source

All Articles