Link to home
Create AccountLog in
Avatar of rafique12
rafique12

asked on

How to show product categories in vertical left sidebar in Magento?

Hello guys,

I am having trying to display product categories in the left sidebar of my Magento store using a tabbed dropdown list.

I am having difficulty getting the list to show in my magento store and would like some assistance please...?

Here is what I have so far:
<div class="block-nav left-nav">
<ul class="nav nav-tabs">
  <li class="dropdown">
    <a class="dropdown-toggle"
       data-toggle="dropdown"
       href="#">
        Shop by category
        <b class="caret"></b>
      </a>
    <ul class="dropdown-menu">
<li><?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?></li>    
    </ul>
  </li>
</ul>
</div>

Open in new window

Avatar of COBOLdinosaur
COBOLdinosaur
Flag of Canada image

Yhat bit of code does not help much.  It does not give us any context.  A link to the page would be much more helpful.

Cd&
Avatar of rafique12
rafique12

ASKER

Sorry, I'm working on my local host at the moment.
ASKER CERTIFIED SOLUTION
Avatar of Php_expert
Php_expert
Flag of India image

Link to home
membership
Create an account to see this answer
Signing up is free. No credit card required.
Create Account
Thankyou for the sending me the link...!

I'm after something very similar to this: http://www.amazon.co.uk/ Where the navigation on the left is displayed in a dropdown box...

I have the css (bootstrap) but I can't get the categories to show using a foreach loop... I'm really stuck.
Avatar of Chris Stanyon
What class are you using to render this template. To have access to the getStoreCategories()  function, you need to use the catalog/navigation class. I think you can probably also use the catalog/category helper. You also need to have the foreach loop outside of the LIs:

<?php $helper = $this->helper('catalog/category') ?>
<?php $categories = $this->getStoreCategories() ?>
<ul>
<?php foreach($categories as $category): ?>
    <li><a href="<?php echo $helper->getCategoryUrl($category) ?>"><?php echo $this->escapeHtml($category->getName()) ?></a></li>
<?php endforeach; ?>
</ul>

Open in new window

Didn't realise you got back to pal.

I'm using the boostrap css framework this time round and I'm still having difficulty. Here's what I have.

<?php $helper = $this->helper('catalog/category') ?>
<?php $categories = $this->getStoreCategories() ?>
<ul class="nav visible-tablet visible-phones hidden-desktop">
<?php foreach($categories as $category): ?>
    <li class="dropdown">
    	<a href="#" class="dropdown-toggle" data-toggle="dropdown">
      Account
      <b class="caret"></b>
    </a>
    <ul class="dropdown-menu">
    <li>	<a href="<?php echo $helper->getCategoryUrl($category) ?>"><?php echo $this->escapeHtml($category->getName()) ?></a></li>
    </ul>	
    </li>
<?php endforeach; ?>
</ul>

Open in new window

When you say you are having problems getting this to work, what exactly do you mean? Is this a CSS styling issue, or can you not get any categories to display at all.

Are you sure you're using the catalog/navigation class (Magento PHP Class not a CSS Class). Somewhere in your layout files, you will be declaring a block for the vertical navigation which will define the class (block type) to use and the template to render. Something like this:

<reference name="left">
    <block type="catalog/navigation" name="vertical.categories" as="vertNav" template="catalog/navigation/vert.phtml" />
</refereance>

Open in new window

The block type is important and without it, you can't call $this->getStoreCategories() in your template.
After hours and hours of trying my own method I revisited your recommendation and it does exactly what I need it to.

Thanks alot!