Magento

eCommerce Software for Online Growth

Magento Forum

From setting up your store to managing your products, pages and promotions to generating detailed reports, the Magento User Guide empowers the user to utilize the platform for all of its vast capacity.
Available in eBook and Print formats – Download Now!!!
   
Page 2 of 4
Categories on the homepage - someone please help! 
 
br_olli
Member
 
Total Posts:  56
Joined:  2008-10-23
 

I hope anyone of you can help me. I searched several sites an threads which describes and seemingly solve my problem. I thought also i understood the magento template-system but apperently i dont…

So my problem: i need a vertical category menu an i did following:
1. I copied my template/catalog/navigation/left.phtml and wrote a simple list:

<h4 class="register-bg"><?php echo $this->__('Products'?> </h4>
<
div class="box-gradient-wrap">
    <
div class="box layered-nav">
        <
div class="head">
        </
div>
        <
div class="border-creator">
            <
div class="narrow-by">
                <
dl id="narrow-by-list">
                    <
dd>
                        <
ol>
                         
<?php foreach ($this->getStoreCategories() as $_category): ?>
                            
<li>
                                
<?php echo $this->drawItem($_category?> 
                            
</li>
                        
<?php endforeach ?>
                        
</ol>
                    </
dd>
                </
dl><script type="text/javascript">decorateDataList('narrow-by-list')</script>
            
</div>
        </
div>
    </
div>
</
div>
and i saved it in the same folder under: left_nav.phtml

2. I opened my layout/catalog.xml an added this:

.....
  <
reference name="left">
            <
block type="catalog/navigation" name="catalog.leftnav" template="catalog/navigation/left_nav.phtml"/> <!-- <- my edit -->
            <
block type="core/template" name="left.permanent.callout" template="callouts/left_col.phtml">
....

That should be all to do. Cause if i switch left_nav.phtml to another template file it appears on every site as it should be.
After this doesnt work i tried to include it in the magento backen under CMS-Page “Home” but there was also no change on the frontend.

What did i forget?? I dont know what to try next and the docus arent big help.

greets from germany

 
Magento Community Magento Community
Magento Community
Magento Community
 
vilke
Jr. Member
 
Total Posts:  7
Joined:  2008-11-03
 
craigboi87 - 15 August 2008 03:35 AM

had the same problem hope this helps. its the most clear and simple way of doing it (:

1. Create a file named “left_menu1.phtml” in “magento\app\design\frontend\default\default\template\catalog\navigation\”


left_menu1.phtml

<div class="box layered-nav">
    <
div class="head">
      <
h3><?php echo $this->__('Browse By'?></h3>
    </
div>
    <
div class="border-creator">
      <
div class="narrow-by">
           <
dl id="narrow-by-list">
           
         <
dd>
         <
ol>        
        
<?php foreach ($this->getStoreCategories() as $_category): ?>
            
<dt>
             <
a href="<?php echo $this->getCategoryUrl($_category) ?>"<?php if ($this->isCategoryActive($_category)): ?> class="active"<?php endif ?>><?php echo $this->htmlEscape($_category->getName()) ?></a>
            </
dt>
        
<?php endforeach ?>
        
       
</ol>
      </
dd>
      </
dl><script type="text/javascript">decorateDataList('narrow-by-list')</script>
    
</div>
   </
div>
</
div>
2. Go to: CMS->Manage Pages, and click in Homepage, select in the left “Custom Design” and write this code in “Layout Update XML”:
<reference name="left">
    <
block type="catalog/navigation" name="catalog.leftnavig" before="-" template="catalog/navigation/left_menu1.phtml"/>
</
reference>
3. save it

to be honest i think this should be a sticky somewhere as its got to be a common ass question (:

I did all this and it’s working. But my shop contains 3 languages and when I switch to other langauge, the categories names are still shown in default language, though they are translated accordingly.. What should be changed that when I switch between languages, the cateogyr menu would show in appopriate language as well?

 
Magento Community Magento Community
Magento Community
Magento Community
 
br_olli
Member
 
Total Posts:  56
Joined:  2008-10-23
 

I solved this problem in a very easy way smile

You can include your category menu if you simply remove this code-line in your left.phtml file:

Line 1:

<?php if (!Mage::registry('current_category')) return ?>

Hope this helps somebody.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Weezers Gifts
Member
 
Total Posts:  71
Joined:  2008-11-08
PA
 

edited took down as I was displaying errors.  Will put it back up shorly.

None the less I am still not getting it laid out right.  I am currently using the newest release of Magento.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Weezers Gifts
Member
 
Total Posts:  71
Joined:  2008-11-08
PA
 

Ok good news I got it to work on one of my other sites.

Now 2 questions:

1) How do I get this left nav to show on all pages?  Seems when I click on a link from it and go to that category the left nav box disappears.

2) How do I remove the top menu from the site as I don’t need it?

 
Magento Community Magento Community
Magento Community
Magento Community
 
reefnut
Member
 
Total Posts:  69
Joined:  2008-07-05
 

For your left navigation i use the following code that i found in the forum a while back and it shows on all pages I use version 1.1.6 and you can see it in action at http://www.hotpricedgiftshop.com.

to create a left hand navigation:

Creating a vertical left-side category menu really is pretty easy. All that you have to do is create a new (really just copied) template and adjust the css. For the navigation, magento outputs an unordered-list, making it pretty easy to put in a vertical format using a couple of lines of css. There are three things that need to be done in order to output a vertical category structure:
1. Create vertical category template
2. Create CSS
3. Reference in xml files.

1. Create Vertical Category Template
Open template/catalog/navigation/top.phtml. Which should look like

<div class="header-nav-container">
<div class="header-nav">
<h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
<ul id="nav">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
</ul>
</div>
<?php echo $this->getChildHtml('topLeftLinks') ?>
</div> Change:
header-nav-container to vertical-nav-container
header-nav to vertical nav
nav to nav_vert

Which would make look like:

<div class="vertical-nav-container">
<div class="vertical-nav">
<h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
<ul id="nav_vert">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
</ul>
</div>
<?php echo $this->getChildHtml('topLeftLinks') ?>
</div>

Save this file as template/catalog/navigation/vert_nav.phtml.
2. Create CSS for vertical menu
Now that you have the template for the vertical navigation, you need to adjust the css to make it vertical. Copy the css below into you menu.css file:

/**********************************************Vertical Nav ****************************************/
#nav_vert { padding:0 20px; font-size:1em; z-index:999; width:190px; }

/************** ALL LEVELS *************/ /* Style consistent throughout all nav levels */
#nav_vert li {
width:175px;
list-style:none;
position:relative;
text-align:left;
}
#nav_vert li.over { z-index:999; }
#nav_vert li.active { z-index:999; } /* to prevent the li separator from showing through on mouseover on li */
#nav_vert a { line-height:1.3em; }
#nav_vert a, #nav_vert a:hover { display:block; text-decoration:none; }
#nav_vert span { display:block; cursor:pointer; }

/************ 1ST LEVEL ***************/
#nav_vert li { float:left; background:url(../images/nav_bg.gif) repeat-x 50%; height:30px; margin-right:1px; }
#nav_vert li.active a { color:#4c6a16; }
#nav_vert a {

float:left;
padding:5px 12px 6px 8px;
color:#4c6a16;
font-weight:bold;
font-family:Trebuchet MS;
font-size:13px;}
#nav_vert li.over a, #nav_vert a:hover { color:#CCCCCC; }

/************ 1ST LEVEL RESET ************/
#nav_vert ul li, #nav_vert ul li.active {

float:none;
height:auto;
background:none;
margin:0;
}
#nav_vert ul a, #nav_vert ul a:hover {
float:none;
padding:0;
background:none;
}
#nav_vert ul li a { font-weight:normal !important; }

/************ 2ND LEVEL ***********/
#nav_vert ul {
position: absolute;
width:15em;
margin-left:125px;
top:5px;
left:-10000px;
border:1px solid #666666;
}

/* Show menu */
#nav_vert li.over ul { left:0; }
#nav_vert li.over ul ul { left:-10000px; }
#nav_vert li.over ul li.over ul { left:100px; }

#nav_vert ul li a { background:#FFFFFF/*#ecf3f6*/; }
#nav_vert ul li a:hover { background: #F2F1D2; /*#d5e4eb;*/ }
#nav_vert ul li a span { background:url(../images/nav_divider.gif) repeat-x 0 100%; }
#nav_vert ul li a, #nav_vert ul li a:hover { color:#2f2f2f !important; }
#nav_vert ul span, #nav_vert ul li.last li span { padding:3px 15px 4px 15px;}
#nav_vert ul li.last span { background:none; }

/************ 3RD+ LEVEL ************/

#nav_vert ul ul { top:5px;}
#nav_vert ul ul ul { left:-10000px;}
#nav_vert li.over ul li.over ul ul { left:-10000px;}
#nav_vert li.over ul li.over ul li.over ul { left:100px; }

/* Fix for the IE bug */

#nav_vert iframe {
position: absolute;
left: -1px;
top: 0;
z-index: -1;
filter: progid:DXImageTransform.Microsoft.Alpha(style=0,opacity=0);
}

Note: The css is essentially the same for the horizontal nav, except for two spots. nav_vert and nav_vert li. Notice, we put a width on these two items, which will restrict the category menu to the width of the column, thus creating a vertical, rather than horizontal menu, which doesn’t have a defined width for the line items. You’ll also notice that we created a new container and box for the vertical menu called vertical-nav-container and vertical-nav. these allow for additional markup and styling that can be added to the main boxes.css file. Here, I will leave them blank. Also, please note that the above css was copied and altered from one of our test sites, so it may reference background-images that you do not have. Like I said the important think is putting the width restriction on the main vert_nav div and the vert_nav li. The rest can be customised for your site.

3. Reference your new menu
Ok, now you have a new vertical category menu that is not showing up anywhere. Great. You need to reference the new template in the catalog.xml for your template. In the <default></default> block of you catalog.xml file add:
<reference name="left">
<block type="catalog/navigation" name="catalog.vertnav" template="catalog/navigation/vert_nav.phtml" />
</reference>
The default block should be at the top of your catalog.xml file.

 
Magento Community Magento Community
Magento Community
Magento Community
 
reefnut
Member
 
Total Posts:  69
Joined:  2008-07-05
 

To remove the links from the top just comment out that portion of script it can be found here app/design/frontend/default/default/template/catalog/navigation/top.phtml. It should look like this when done.

<!-- <div class="header-nav-container">
<div class="header-nav">
<h4 class="no-display"><?php echo $this->__('Category Navigation:') ?></h4>
<ul id="nav">
<?php foreach ($this->getStoreCategories() as $_category): ?>
<?php echo $this->drawItem($_category) ?>
<?php endforeach ?>
</ul>
</div>
<?php echo $this->getChildHtml('topLeftLinks') ?>
</div> -->

Notice the comments at the beginning and the end.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Weezers Gifts
Member
 
Total Posts:  71
Joined:  2008-11-08
PA
 

HI reefnut,

Thanks for the help and the code.

Couple of things.  If you go here http://www.outside-decoratives.com/ you will see the menu to the left. 

1) How would I get the menu above the boxes ( would really like to know how to get rid of the top box anyways and need to search that)

2) The menu doesn’t stay when I click on a link.  It just disappears on me.  I tried it in IE7 as well as Firefox and they both have the same issue.

Also how did you get your Home | FAQ’s Menu like that?  I would want to incorporate that type of menu as well since there is no menu with “Home” in it.

Thanks much again for your help.

 
Magento Community Magento Community
Magento Community
Magento Community
 
Weezers Gifts
Member
 
Total Posts:  71
Joined:  2008-11-08
PA
 

Ok I got issues 1 & 2 solved. 

But I would still like to know how you go the other menu showing in the center. 

Sorry for all the posting.

 
Magento Community Magento Community
Magento Community
Magento Community
 
reefnut
Member
 
Total Posts:  69
Joined:  2008-07-05
 

to add links to the center of the home page and all other pages edit the app/design/frontend/default/default/template/page/1columm.phtml or whichever one or ones you plan to use on your site. Place the links after <!-- [start] middle -->
<div class="middle-container">

and before

<div class="middle col-1-layout">

 
Magento Community Magento Community
Magento Community
Magento Community
 
infinite
Jr. Member
 
Total Posts:  1
Joined:  2008-10-30
 

With reference to Post #23, How did you get the problem of disapearing menu got solved? It will help if you can share the details.

Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
platinumtackle
Member
 
Total Posts:  40
Joined:  2008-09-30
 

OK so I have two questions.  The first is that there is a call to SetOrder in 1.2.0.1

Retrieve child categories of current category
     
*
     * @return 
Varien_Data_Tree_Node_Collection
     
*/
    public function 
getCurrentChildCategories($sort_by ''$sort_order 'asc')
    
{
        $layer 
Mage::getSingleton('catalog/layer');
        
$category   $layer->getCurrentCategory();
        
/* @var $category Mage_Catalog_Model_Category */
        
$collection Mage::getModel('catalog/category')->getCollection();
        
/* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
        
$collection->addAttributeToSelect('url_key')
            ->
addAttributeToSelect('name')
            ->
addAttributeToSelect('is_anchor')
            ->
addAttributeToFilter('is_active'1)
            ->
addAttributeToSort($sort_by$sort_order)
            ->
addIdFilter($category->getChildren())
            ->
setOrder('position''ASC')
            ->
joinUrlRewrite()
            ->
load();

        
$productCollection Mage::getResourceModel('catalog/product_collection');
        
$layer->prepareProductCollection($productCollection);
        
$productCollection->addCountToCategories($collection);
        return 
$collection;
    
}

Do I need this or do I need to change the example you provided?

The second question is I want to be able to select a random set of child categories and have been looking at how product gets the random product list.  Can you help me figure out how to set the collection to select random set of child categories?

protected function _getProductCollection()
    
{
        
if (is_null($this->_productCollection)) {
            $collection 
Mage::getResourceModel('catalog/product_collection');
            
Mage::getModel('catalog/layer')->prepareProductCollection($collection);
            
$collection->getSelect()->order('rand()');
            
$collection->addStoreFilter();
            
$numProducts $this->getNumProducts() ? $this->getNumProducts() : 3;
            
$collection->setPage(1$numProducts);

            
$this->_productCollection $collection;
        
}
        
return $this->_productCollection;
    
}

 
Magento Community Magento Community
Magento Community
Magento Community
 
moleygunn
Member
 
Total Posts:  48
Joined:  2008-11-25
 

I was getting this error Call to a member function count() on a non-object in left.phtml

I fixed it by copying the most recent left.phtml from the default frontend folder to my own custom frontend folder

 
Magento Community Magento Community
Magento Community
Magento Community
 
Datashock
Jr. Member
 
Total Posts:  2
Joined:  2009-03-12
Serbia
 
rzazueta - 14 August 2008 10:40 PM

First, I added a new method in the app/code/core/Mage/Block/Navigation.php:

public function getChildCategories($categoryId)
    
{
          $category 
Mage::getModel('catalog/category');
          if(
$category->checkId($categoryId) === false{
              
return false;
          
}
        $layer 
Mage::getSingleton('catalog/layer');
        
$category->load($categoryId);
        
$layer->setCurrentCategory($category);
        
/* @var $category Mage_Catalog_Model_Category */
        
$collection Mage::getModel('catalog/category')->getCollection();
        
/* @var $collection Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Collection */
        
$collection->addAttributeToSelect('url_key')
            ->
addAttributeToSelect('name')
            ->
addAttributeToSelect('is_anchor')
            ->
addAttributeToFilter('is_active'1)
            ->
addIdFilter($category->getChildren())
            ->
joinUrlRewrite()
            ->
load();

        
//$productCollection = Mage::getResourceModel('catalog/product_collection');
        //$layer->prepareProductCollection($productCollection);
        //$productCollection->addCountToCategories($collection);
        
return $collection;
    
}

All works fantastic on my local server with 1.3.0, but when I uploaded it on test server where is 1.3.1 version (not sure that has any meaning) I got Error:

Fatal error: Call to undefined method Mage_Catalog_Model_Resource_Eav_Mysql4_Category_Flat_Collection::joinUrlRewrite() in TESTSERVER/app/code/local/Mage/Catalog/Block/Navigation.php on line 245

I don’t get it!!!!!! Please help, it’s urgent!!

 Signature 

--
datashock
graphic and web design & development

 
Magento Community Magento Community
Magento Community
Magento Community
 
rwone
Sr. Member
 
Total Posts:  125
Joined:  2009-02-12
 

There are several suggestions here for how to display layered navigation on the home page (ie the ‘Shop By’ module which displays categories and their subcategories etc).  Is there a definitive solution to this anywhere please?

 
Magento Community Magento Community
Magento Community
Magento Community
Magento Community
Magento Community
    Back to top
Page 2 of 4
 
© Copyright 2010 Magento Inc.
Privacy Policy|Terms of Service
Magento Community Count
196425 users|1375 users currently online|363502 forum posts