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

Magento

eCommerce Software for Online Growth

Magento Forum

   
Show only main categories? 
 
MagentoJoe
Sr. Member
 
Total Posts:  119
Joined:  2007-08-31
 

This line of code:

<?foreach ($this->getStoreCategories() as $_category):?>

.. will display all categories.

However, I want a function to just display the Main categories (IE no sub-categories). This is because I want a top-menu to display only the main categories (dont like dropdowns).

Really preciate any fast answer on this one!

 Signature 

Visit http://www.ecommerce-extensions.com for professional Magento templates and widgets.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Anders Rasmussen
Sr. Member
 
Avatar
Total Posts:  165
Joined:  2007-10-16
Denmark
 

Actually, that call only pulls the main categories. The $this->drawItem($_category) inside the for loop then writes the category and sub categories. Instead, you can just do something like this:

<?php foreach ($this->getStoreCategories() as $_category): ?>
    
<a href="<?php echo $this->getCategoryUrl($_category); ?>"><?php echo $this->htmlEscape($_category->getName()); ?></a>
<?php endforeach ?>

 Signature 

Anders Rasmussen
Crius (in Danish)

 
Magento Community Magento Community
Magento Community
Magento Community
 
MagentoJoe
Sr. Member
 
Total Posts:  119
Joined:  2007-08-31
 

Yep, one of our developers figured the exact same thing out around 30 minutes ago wink

Thanks alot anyway Anders!

 Signature 

Visit http://www.ecommerce-extensions.com for professional Magento templates and widgets.

 
Magento Community Magento Community
Magento Community
Magento Community
 
WisdOMbooks
Sr. Member
 
Avatar
Total Posts:  145
Joined:  2007-08-31
Kolkata (Calcutta) - INDIA
 


Forgive this intrusion by an almost-newbie
into your high-level programming exchangecool smile
but when you suggested the code, as in here

aFFi
 <?foreach 
($this->getStoreCategories() as $_category):?> 

Anders
 <?php 
foreach ($this->getStoreCategories() as $_category): ?>
    
<a href="<?php echo $this->getCategoryUrl($_category); ?>"><?php echo $this->htmlEscape($_category->getName()); ?></a>
<?php endforeach ?>

within / where exactly the above code has to be put ?

I just tried (in my immense programming ignorance red face 
to dump it as-it-is in my homepage CMS
but it failed miserably… cough! cough ! sick 

Yes, the original idea of mine was same as yours:
to put ALL the categories inside the homepage,
or at least the main ones.

Thank you for your precious time.

A n g e l o

 Signature 

WisdOMbooks.com : Select Publications on Indian Civilization

 
Magento Community Magento Community
Magento Community
Magento Community
 
Anders Rasmussen
Sr. Member
 
Avatar
Total Posts:  165
Joined:  2007-10-16
Denmark
 

@WisdOMbooks

In app/design/frontend/default/default/template/catalog/navigation/top.phtml (if you are using the default template) replace this:

<?php foreach ($this->getStoreCategories() as $_category): ?>
    <?php 
echo $this->drawItem($_category?>
<?php 
endforeach ?>

with this:

<?php foreach ($this->getStoreCategories() as $_category): ?>
    
<a href="<?php echo $this->getCategoryUrl($_category); ?>"><?php echo $this->htmlEscape($_category->getName()); ?></a>
<?php endforeach ?>

 Signature 

Anders Rasmussen
Crius (in Danish)

 
Magento Community Magento Community
Magento Community
Magento Community
 
WisdOMbooks
Sr. Member
 
Avatar
Total Posts:  145
Joined:  2007-08-31
Kolkata (Calcutta) - INDIA
 

I did try to use your code, dear Anders,
but nothing much happened there at the top where the categories are,
a part some dis-alignement of the text.

My point was to add categories (and sub-cats and sub-cats, etc.) to the home page CMS area,
but your suggested code actually belongs to the top.html area…
unless I am really missing something !

 Signature 

WisdOMbooks.com : Select Publications on Indian Civilization

 
Magento Community Magento Community
Magento Community
Magento Community
 
Anders Rasmussen
Sr. Member
 
Avatar
Total Posts:  165
Joined:  2007-10-16
Denmark
 

That’s right, my code belongs to the top menu, and it prints only the main categories instead of main + sub categories as aFFi asked for. In the default template, when you float your mouse over a main category in the top menu, a drop down menu will show sub menus (if you have any). With my code, it won’t.

I don’t know how to display categories in the CMS area.

 Signature 

Anders Rasmussen
Crius (in Danish)

 
Magento Community Magento Community
Magento Community
Magento Community
 
WisdOMbooks
Sr. Member
 
Avatar
Total Posts:  145
Joined:  2007-08-31
Kolkata (Calcutta) - INDIA
 
Anders Rasmussen -

That’s right, my code belongs to the top menu, and it prints only the main categories instead of main + sub categories as aFFi asked for. In the default template, when you float your mouse over a main category in the top menu, a drop down menu will show sub menus (if you have any). With my code, it won’t.

Oh! I can see, now… Sorry, I did not get it, at first.
Thank you: this code may be really useful
to those who need only main categories in their menu.

don’t know how to display categories in the CMS area.

OK. Thank you in any case.

Anybody else has a possible solution in mind for this?

A n g e l o

 Signature 

WisdOMbooks.com : Select Publications on Indian Civilization

 
Magento Community Magento Community
Magento Community
Magento Community
 
schmelzgeist
Sr. Member
 
Total Posts:  92
Joined:  2008-05-27
Marzipane World Capital (Lübeck, Germany)
 

I wanted just one Category (aptly named ‘Products’) to return its Subcategories. sounds trivial but as of right now i’m a bit stuck by ‘Varien_Data_Tree_Node_Collection’ as return type what s this and how do i get the name of my beloved Category?  any suggestions?  smile

 Signature 

WE have no future because our Present is too volatile.We have only riskmanagement.
The spinning of the given moment´s scenario. *Pattern Recognition.W.Gibson*

 
Magento Community Magento Community
Magento Community
Magento Community
 
nuspace media
Jr. Member
 
Avatar
Total Posts:  3
Joined:  2008-07-31
 
Anders Rasmussen - 28 May 2008 04:20 AM

Actually, that call only pulls the main categories. The $this->drawItem($_category) inside the for loop then writes the category and sub categories. Instead, you can just do something like this:

<?php foreach ($this->getStoreCategories() as $_category): ?>
    
<a href="<?php echo $this->getCategoryUrl($_category); ?>"><?php echo $this->htmlEscape($_category->getName()); ?></a>
<?php endforeach ?>

Thanks for the code. One thing you might want to add is the <li> tags before and after each item. Unless of course you meant to remove the items from the nav list.

<?php foreach ($this->getStoreCategories() as $_category): ?>
    
<li><a href="<?php echo $this->getCategoryUrl($_category); ?>"><?php echo $this->htmlEscape($_category->getName()); ?></a></li>
<?php endforeach ?>

 Signature 

- http://www.nuspacemedia.com -

 
Magento Community Magento Community
Magento Community
Magento Community
 
Richard H
Jr. Member
 
Total Posts:  12
Joined:  2008-04-07
 

edit: wrong post, how stupid…

should have been in http://www.magentocommerce.com/boards/viewthread/17153/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Brightwork
Jr. Member
 
Total Posts:  12
Joined:  2008-03-18
 

I’m having a similar, but inverse problem with the menu on my homepage - On the homepage only, the menu only shows the top level categories.  The menu won’t drop-down to show the sub-categories.  This only happens on the homepage.  The drop-down works fine once you browse to the category page.  You can see what I’m talking about here:

http://www.brightworkcreative.com/clients/cf

Does anyone know what might be causing this?

Thanks,
Scott

 
Magento Community Magento Community
Magento Community
Magento Community
 
Nick McCally
Jr. Member
 
Total Posts:  1
Joined:  2008-09-05
 

This still displays my disabled category links in the source. Anyone know how to fix that?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
 
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
50119 users|452 users currently online|102256 forum posts