Call-back icon  Sales: Call 877.832.5289 (N America)|310.295.4144 (International)

Magento

eCommerce Software for Online Growth

Magento Forum

   
Page 1 of 2
Using the CMS and the menu
 
matt adams
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2007-09-06
 

So I see that when i add new categories under the root, they dynamically populate the main navigation. Is there a way to have CMS pages also auto populate this navigation? or must I manually add or remove pages here:

the file called ‘top.phtml’ in app/design/frontend/default/default/template/catalog/navigation/ and make the following change:-

<div class="header-nav-container">
    <
div class="header-nav">
        <
h4 class="no-show">Category Navigation:</h4>
        <
ul id="nav">

        <!-- 
HOME BUTTON HACK -->
        <
li><a href="http://www.yourshop.com/">Home</a></li>
        <!-- 
HOME BUTTON HACK -->

        
<?foreach ($this->getStoreCategories(10) as $_category):?>
            <?
=$this->drawItem($_category)?>
        <?endforeach?>
        
</ul>
    </
div>
</
div>
[

 
Magento Community Magento Community
Magento Community
Magento Community
 
kharisma
Member
 
Total Posts:  64
Joined:  2007-10-18
Australia
 

I have been trying to add CMS page links as well (although not seeking to auto-poulate). The changes I have made are:

1. Admin > CMS > Static Block

Created a static block called main_nav, similar to footer_links for the footer.

2. app/design/frontend/custom/default/layout/page.xml

Added to header block:

<!-- Use CMS pages in top menu -->
<
block type="cms/block" name="top_menu" as="topMenu">
    <
action method="setBlockId"><block_id>top_menu</block_id></action>
</
block>

3. app/design/frontend/custom/default/layout/cms.xml

Added to default block:

<default>
    <!-- For 
header main navigation links -->
    <
reference name="main_nav">
        <
action method="setBlockId"><block_id>main_nav</block_id></action>
    </
reference>

    <
reference name="footer_links">
        <
action method="setBlockId"><block_id>footer_links</block_id></action>
    </
reference>

</default>

4. app/design/frontend/xmpm/default/template/page/html/header.phtml

Changed topMenu to main_nav

<?=$this->getChildHtml('main_nav')?>

So far, nothing appears.

What do I need to do differently?

 
Magento Community Magento Community
Magento Community
Magento Community
 
kharisma
Member
 
Total Posts:  64
Joined:  2007-10-18
Australia
 

Have got it working, but only when applied to a website or the default config. Does not seem to work if implemented at store level, so needs to be implemented higher up the chain.

Also, must be a mod of the default package.

Edit app/design/frontend/default/custom/page.xml

<block type=“page/html_header” name=“header” as=“header”>
    <
block type="page/html_toplinks" name="top.left.links" as="topLeftLinks"/>
    <
block type="page/html_toplinks" name="top.right.links" as="topRightLinks"/>

    <!
– Store switcher is now in header –>
    <
block type=”core/store_switcher” name=”store_switcher” as=”storeSwitcher” template=”core/stores.phtml”/>

    <!
– Use CMS pages in top menu –>
    <
block type=”cms/block” name=”main_menu” as=”mainMenu”>
        <
action method=”setBlockId”> <block_id>main_menu</block_id> </action>
    </
block>
</
block>

Edit app/design/frontend/default/custom//cms.xml by adding to <default>:

<reference name=“main_menu”>
     <
action method=“setBlockId”><block_id>main_menu</block_id></action>
</
reference>

Use Admin/CMS/Static block to create ‘main_menu’ with chosen links

<div class=”header-nav-container”>
    <
div class=”header-nav”>
        <
ul id=”nav”>
            <
li><a href=”{{store url=''}}services”>Services</a></li>
            <
li class=”last”><a href=”{{store url=''}}products”>Products</a></li>
        </
ul>
    </
div>
</
div>

 
Magento Community Magento Community
Magento Community
Magento Community
 
chinesedream
Guru
 
Total Posts:  744
Joined:  2007-08-31
San Francisco, CA
 

Thanks both, two methods work! Can one tell which one is better approach?

 
Magento Community Magento Community
Magento Community
Magento Community
 
kharisma
Member
 
Total Posts:  64
Joined:  2007-10-18
Australia
 

I prefer my approach because it is easier to make changes to the menu, simply by editing the CMS block, whereas using the first method, you would have to keep finding that file in your code and making the changes there. Creating a CMS block is more consistent with the rest of Magento, and how the footer links are done.

 
Magento Community Magento Community
Magento Community
Magento Community
 
jajaklar82
Jr. Member
 
Avatar
Total Posts:  4
Joined:  2008-02-23
 

this code hacking for such a simple thing is why I hope for some good joomla integration… magento is really a shop system not a CMS

 Signature 

yoroshiku
surprised

 
Magento Community Magento Community
Magento Community
Magento Community
 
Moshe
Magento Team
 
Avatar
Total Posts:  1771
Joined:  2007-08-07
Los Angeles
 

@jajaklar82: I’m curious to find out what do you mean by “code hacking”.

In my understanding “code hacking” means changing core or module PHP files (Controller or Model part of MVC)

In the solutions above there was only layouts and templates editing (View part of MVC)

 Signature 

- I would love to change the world, but they won’t give me the source code -

 
Magento Community Magento Community
Magento Community
Magento Community
 
Ross
Sr. Member
 
Avatar
Total Posts:  230
Joined:  2007-08-31
Scarborough, North Yorkshire, UK
 

@Moshe - You are right “it’s only templates and layouts”, but for store owners and users - who may not even know HTML - this kind of thing looks like “code hacking”.

People who use programs like Joomla expect that they can change navigation and blocks with a GUI, not by using XML configuration (layout) files and PHP/HTML template files.

For me it’s no problem, but for a lot of people this is way too much.

 Signature 

Ross Kendall - Web Developer - rosskendall.com
Client Magento websites:
- Out of the Ark Music (UK): a leading publisher of children’s musicals
- Dottie Lottie: children’s clothing boutique

 
Magento Community Magento Community
Magento Community
Magento Community
 
chinesedream
Guru
 
Total Posts:  744
Joined:  2007-08-31
San Francisco, CA
 

Hi Kharisma,

Can you update your code, or is it still works?  I don’t seem able to get it working. The code you posted above, worked for me in v0.7x, butthe cms.xml file had changed since v0.8x, so I didn’t bother to update it and had used Matt’s method.

Now I wanted to use yours method, but I am confused with the comment in the cms.xml file:

<reference name="footer">
            <
block type="cms/block" name="cms_footer_links" before="footer_links">
                <!--
                    
The content of this block is taken from the database by its block_id.
                    
You can manage it in admin CMS -> Static Blocks
                
-->
                <
action method="setBlockId"><block_id>footer_links</block_id></action>
            </
block>
        </
reference>

I don’t know this is differ to which one, the block type or action method.
‘ <!-- The content of this block is taken from the database by its block_id.
You can manage it in admin CMS -> Static Blocks
-->

 
Magento Community Magento Community
Magento Community
Magento Community
 
douzie
Jr. Member
 
Total Posts:  10
Joined:  2008-03-27
 

I want to add a new link to the top menu (next to My Account, My Cart, Checkout, etc.). So I created a new CMS page (via CMS-->Manage Pages). I enabled the page, set its SEF identifier, layout etc. - I can even preview it via the admin panel. However, I can’t for the life of me figure out how to make it show up on my frontend! I obviously realize that I need to manually add it “somewhere” - but where???

Thanks.

 
Magento Community Magento Community
Magento Community
Magento Community
 
mathilda
Jr. Member
 
Total Posts:  15
Joined:  2008-04-04
Frankfurt / Main
 

i tried Kharismas method and changed page.xml and cms.xml and added a static block , but I got an error message referring to

Warningsimplexml_load_string(): Entityline 62parser error StartTaginvalid element name  in /srv/www/.../httpdocs/app/code/core/Mage/Core/Model/Layout/Update.php on line 276
Trace
:
Maybe after the latest update Kharismas code has to be modified? Has someone a solution for this?
Cheers

 
Magento Community Magento Community
Magento Community
Magento Community
 
Lance Monotone
Member
 
Avatar
Total Posts:  57
Joined:  2008-04-16
North Adams, MA. 01247
 

This has to be without a doubt the most frustrating thing I’ve tried to do so far, maybe with the exception of figuring out that you need a root category for any of your products to show.  I think Magento is fantastic and very flexible but the documentation is really lacking and needs to be updated before new releases.

Anyway, this is how I did it:

1. I made copies of these files and put them in my custom theme folder so as not to overwrite the default files, ie, ’app/design/frontend/default/my_theme‘ instead of ’app/design/frontend/default/default‘.  Getting a custom theme to display is another PITA. 

2. I created a static block in the CMS with the id of ’top-nav‘.

3. cms.xml

I placed this inside the <default> tag (above <reference name="footer">) because I want it on every page.

<reference name="top-nav">
     <
action method="setBlockId"><block_id>top-nav</block_id></action>
</
reference>

4. page.xml

I placed this markup inside the ’<block type="page/html_header" name="header" as="header">‘ tag because I want it to appear in the header.

<block type="page/html_header" name="header" as="header">
     <
block type="page/template_links" name="top.links" as="topLinks"/>
     <
block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
     <
block type="core/text_list" name="top.menu" as="topMenu"/>  

<!-- 
[begin] top-nav -->
     <
block type="cms/block" name="top-nav" as="topNav">
          <
action method="setBlockId"><block_id>top-nav</block_id></action>
     </
block>         
<!-- 
[end] top-nav -->

</
block>

5. header.phtml

Then, I directed the template file to call and display the block with <?php echo $this->getChildHtml('topNav') ?> after the top menu that displays the categories.

<?php echo $this->getChildHtml('topMenu'?>

<?php 
echo $this->getChildHtml('topNav'?>

I hope this helps someone.

 
Magento Community Magento Community
Magento Community
Magento Community
 
CKD
Member
 
Avatar
Total Posts:  31
Joined:  2007-11-21
Saitama, Japan
 

@Lance Monotone
Thank you so much.  I have been cracking my head on my desk all day for this one.  Simple when you see it, and you think that this would be in the designers guide as one of the exercises or something.  Anyways, this is great.

Thanks!,

CKD

Lance Monotone - 30 May 2008 06:51 AM

This has to be without a doubt the most frustrating thing I’ve tried to do so far, maybe with the exception of figuring out that you need a root category for any of your products to show.  I think Magento is fantastic and very flexible but the documentation is really lacking and needs to be updated before new releases.

Anyway, this is how I did it:

1. I made copies of these files and put them in my custom theme folder so as not to overwrite the default files, ie, ’app/design/frontend/default/my_theme‘ instead of ’app/design/frontend/default/default‘.  Getting a custom theme to display is another PITA. 

2. I created a static block in the CMS with the id of ’top-nav‘.

3. cms.xml

I placed this inside the <default> tag (above <reference name="footer">) because I want it on every page.

<reference name="top-nav">
     <
action method="setBlockId"><block_id>top-nav</block_id></action>
</
reference>

4. page.xml

I placed this markup inside the ’<block type="page/html_header" name="header" as="header">‘ tag because I want it to appear in the header.

<block type="page/html_header" name="header" as="header">
     <
block type="page/template_links" name="top.links" as="topLinks"/>
     <
block type="page/switch" name="store_language" as="store_language" template="page/switch/languages.phtml"/>
     <
block type="core/text_list" name="top.menu" as="topMenu"/>  

<!-- 
[begin] top-nav -->
     <
block type="cms/block" name="top-nav" as="topNav">
          <
action method="setBlockId"><block_id>top-nav</block_id></action>
     </
block>         
<!-- 
[end] top-nav -->

</
block>

5. header.phtml

Then, I directed the template file to call and display the block with <?php echo $this->getChildHtml('topNav') ?> after the top menu that displays the categories.

<?php echo $this->getChildHtml('topMenu'?>

<?php 
echo $this->getChildHtml('topNav'?>

I hope this helps someone.

 
Magento Community Magento Community
Magento Community
Magento Community
 
tin_soldier
Jr. Member
 
Total Posts:  7
Joined:  2008-08-29
 

This thread is very useful and I’ve managed to get it working following Lance Monotone’s instructions.

Does anyone know how to make these navigation links show <li class="active" to show when you are on a particular page?
This is seen in the top nav in the Modern theme.

 
Magento Community Magento Community
Magento Community
Magento Community
 
doctorlogos
Sr. Member
 
Avatar
Total Posts:  133
Joined:  2008-05-06
 

@tin_soldier, I also want to know how to show a

<li class="active">

Some help?

 
Magento Community Magento Community
Magento Community
Magento Community
 
litews
Member
 
Total Posts:  47
Joined:  2008-05-28
France - Near Toulouse
 

thanks a lot @Lance Monotone, it works fine for me, in fact I used your tutorial to create a static block to customize the top links bar (to add small images between them )

* My Account * My Wishlist * My Cart * Checkout * Log In

 Signature 

Need one click insstall solution for Magento? Then SimpleHelix is for you!

SimpleHelix Hosting - Fast Magento Hosting Solutions
█ Magento-One-Click-Installer And 24/7 Live Support
█ The #1 leader in High-Performance web hosting

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 1 of 2
 
Sales: Call 877.832.5289 (North America) 310.295.4144 (International)
© Copyright 2008 Varien. Magento, eCommerce software, is a trademark of Irubin Consulting Inc. DBA Varien
Privacy Policy|Terms of Service
Magento Community Count
52294 users|454 users currently online|105616 forum posts