# Posting in the Magento forums has been disabled pending the implementation of a new and improved forum solution which should better serve the community.

For new questions please post at magento.stackexchange.com, the community-run support site for the Magento community. We will be providing updates on the new forum solution soon. For questions or concerns please email community@magento.com.

## Magento Forum

Page 1 of 4
 rzazueta   Total Posts:  34 Joined:  2008-07-21 A couple of other things… I turned off the system cache, so changes show up fine. I figured out my question about the callouts (though I’m still unclear on how I could change that on a per-page or per-section basis - i.e. why do I need the left_col callout on every page - what if I want something different for the category main pages?). I changed the left column so that it points to catalog/navigation/left.phtml, but now it’s generating the PHP error “Call to a member function count() on a non-object in C:\working\magento\public_html\app\design\frontend\boardsnmore\default\template\catalog\navigation\left.phtml on line 29”. Looking at the code, this is being caused by a call to the method getCurrentChildCategories() on $this - I’m unclear, though, as to what$this represents. Given that left.phtml is essentially an include file, what object is being instantiated that I’m using $this to refer to it? Any help here? Rob Z. Posted: August 13 2008 | top | # 1  rzazueta Total Posts: 34 Joined: 2008-07-21 Update: I’ve modified the catalog.xml (this is where the callouts were being called) so that the left callout is replaced with the following:   Now I get the PHP error: “Fatal error: Call to a member function getChildren() on a non-object in C:\working\magento\public_html\app\code\core\Mage\Catalog\Block\Navigation.php on line 77” Looking at the code, the getChildren() method is being called on an apparent category objectinstantiated by the following two lines of code: $layer = Mage::getSingleton('catalog/layer');        $category =$layer->getCurrentCategory();  It looks like $category is the boolean false in this situation. What’s happening here? Why is the layer being called? What is its purpose? And why is it returning false for the getCurrentCategory() method? Shouldn’t it return a reference to the root category defined in store management? Rob Z. Posted: August 13 2008 | top | # 2  rzazueta Total Posts: 34 Joined: 2008-07-21 Looking through the code to fix the prior errors, I saw there was a method that appears to be intended to grab all fot je categories for the current store. So, in Navigation.php, I put an if-then around the code instantiating the$category variable that was turning out to be false. Here’s the new code, starting at line 66 in app/code/core/Mage/Catalog/Blobk/Navigation.php:  public function getCurrentChildCategories()    {        $layer = Mage::getSingleton('catalog/layer'); //RDZ - Added to allow the display of categories on the homepage. if(($category   = $layer->getCurrentCategory()) === false) { return$this->getStoreCategories();        }  This actually successfully displayed the second level categories (everything beneath default category) in my assigned root category on the homepage using template/catalog/navigation/left.phtml assigned to the left reference in cms.xml instead of the left_col callout. And now I have a shiny new error. When I click on one oif the categories with an item assigned to it, I get the following PHP error: Fatal error: Call to undefined method Mage_Catalog_Helper_Product::getPriceHtml() in C:\working\magento\public_html\app\design\frontend\boardsnmore\default\template\catalog\product\list.phtml on line 100 How in the world has anyone been able to get this system working? Rob Z. Posted: August 13 2008  |  top  |  # 3
 rzazueta   Total Posts:  34 Joined:  2008-07-21 Well, since no one’s rushed to my aid (or anyone else’s for that matter - c’mon folks, if you find a solution don’t leave it in PMs - this is supposed to be an open source community) I’ve been struggling with this myself. The only solution I’ve come up with involves directly changing the app code. Here’s hoping a new upgrade doesn’t overwrite these changes. Recall my goal was to display the children from a specific category on the homepage. Why I want to do this is irrelevant - it’s a customization issue that should just exist - but I was able to fiond a solution. 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;    }  This takes the numeric category ID and returns a collection of categories that can be used in, say, template/catalog/navigation/left.phtml like so:  getCurrentChildCategories() ?>getChildCategories(3) ?>count()) { ?>
•                             getCategoryUrl($_category) ?>"isCategoryActive($_category)): ?> class="active">htmlEscape($_category->getName()) ?> •  This should display the children for numerical ID 3 as an unordered list in the left hand column of your page, assuming you set it up that way in your layouts. To get the catalog ID, log in as an admin, go to “Catalog->Manage Categories” and click on the category whose children you want to display. You MUST choose a category with children, or this just won’t work. The numeric ID appears in the URL like so: /index.php/admin/catalog_category/edit/id/3/ see that “3” in the URL after id? That’s the numeric ID you’re looking for. So, even with all this setup, the puzzle still didn;t work, and I’m still not clear as to why I had to do this following part. It looked like calling the specific category in the Navigation was doing the job - a call to getName() returned the correct name - but the call to getChildren returned an empty string. Looking through the code, the Category’s Tree class does get called, but it never gets loaded. So I modified the code in app/code/core/Mage/Catalog/Model/Category.php near line 101 in the method “getTreeModelInstance()”:  public function getTreeModelInstance() { if (is_null($this->_treeModel)) {            $this->_treeModel = Mage::getResourceSingleton('catalog/category_tree'); //RZ - Not even sure why this isn't being called like it should be. Adding it.$this->_treeModel->load();        }        return $this->_treeModel; }  That loaded the category tree structure so that the call to getChildren() finally produced something other than a blank string. So, we have success on this front. I’m tossing some karma back into the community pool in the hopes that others may finally post answers to the deluge of questions and problems people are expressing on this board. Rob Z. Posted: August 15 2008 | top | # 4  craigboi87 Total Posts: 90 Joined: 2008-07-18 rite dude i am lost here! what are you trying to achieve? you want categories down the left hand side? Posted: August 15 2008 | top | # 5  craigboi87 Total Posts: 90 Joined: 2008-07-18 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  __('Browse By') ?> getStoreCategories() as$_category): ?>
getCategoryUrl($_category) ?>"isCategoryActive($_category)): ?> class="active">htmlEscape($_category->getName()) ?> decorateDataList('narrow-by-list')  2. Go to: CMS->Manage Pages, and click in Homepage, select in the left â€œCustom Designâ€ and write this code in â€œLayout Update XMLâ€:   3. save it to be honest i think this should be a sticky somewhere as its got to be a common ass question (: Posted: August 15 2008 | top | # 6  mart3ndo Total Posts: 13 Joined: 2008-08-14 Thanks, craigboi87 I managed to get that working on my site, i want to add though that i could only get it working by using the three column design On an unrelated topic, does anyone know how to get products to show up on the front page, like Featured Products, New Products, stuff like that. There’s probably already a post somewhere, but i cant find any, Thanks, Martyn Posted: August 15 2008 | top | # 7  rzazueta Total Posts: 34 Joined: 2008-07-21 I specifically was trying to get the children of a category showing up on the homepage. I wanted to display our store as two separate views at the same time - a list of regular departments (i.e. Men’s Apparel, Women’s Apparel, Accessories, etc.) and a list of brands (O’Neill, Volcom, etc.). The only solution that made sense was to create two categories under the Default Category - “Shop By Brand” and “Shop By Department” - and pull the children only out of the relevant on (i.e. “Shop by Brand” has categories named “O’Neill”, “Volcom”, etc.). I just wanted the brand names as a list on the homepage. So my code above is a bit more advanced than the simple “Show categories on the homepage” a lot of folks had been asking for. But the solution posted for that ought to work - it did for me before I took the next step of figuring this subcat issue out. Rob Z. Posted: August 15 2008 | top | # 8  rzazueta Total Posts: 34 Joined: 2008-07-21 Actually, Craig, adding your post to the wiki documentation may be better than using a sticky. I’m finding the support here frustrating given that, as you mentioned, tons of people ask for help on similar problems and no one seems eager to help. I want to help with the request regarding featured and new items, but I’m still wrapping my head around that. Having said that, here’s a post I found in my research that may help, at least with the featured items: Rob Z. Posted: August 15 2008 | top | # 9  jhutton Total Posts: 19 Joined: 2008-06-24 Rob, Big thanks, dude. I was trying to get my subcategories to show up during product views, and I couldn’t figure out why$category->getChildren() wasn’t returning anything. Now in my view I just do:  getProductId()) {            $product = Mage::getModel('catalog/product')->load($this->getProductId());            Mage::register('product', $product); }$_product = Mage::registry('product');?>load($_path[count($_path) - 1]);    $children_ids = implode(',', Mage::getResourceSingleton('catalog/category_tree')->load()->getChildren($category->getId(), false));    $col = Mage::getModel('catalog/category')->getCollection();$col->addAttributeToSelect('url_key')      ->addAttributeToSelect('name')      ->addAttributeToSelect('is_anchor')      ->addAttributeToFilter('is_active', 1)      ->addIdFilter($children_ids) ->joinUrlRewrite() ->load();$_categories = $col;?> 0): ?>  etc, case anybody is interested. Don’t even have to hack the core. Posted: September 4 2008 | top | # 10  StarGumbo Total Posts: 7 Joined: 2008-02-14 Rob, Thank you much for this addition. I had been trying to get subcategory info to display on the home page and found this to be a great solution. If anyone is interested I added this to display the images and descriptions of the categories as well - in app/code/core/Mage/Catalog/Block/Navigation.php I added the ‘image’ and ‘description’ attributes  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')                /* Add the Image and Description Attributes */                ->addAttributeToSelect('image')                ->addAttributeToSelect('description')                /* End Edit */                ->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; }  and in my custom category-display .phtml file ( app/design/frontend/default/reskin/template/catalog/navigation/catnav-home.phtml )  getChildCategories(6) as$_childCategory): ?>                                getName() ?>            getCategoryUrl($_childCategory) ?>"isCategoryActive($_childCategory)): ?> class="activeNav">            getImageUrl() ?>" alt="getName() ?>" width="75" height="75"/>
getCategoryUrl($_childCategory) ?>">View Our Catalog >  which is referenced in the ‘custom design’ tab for the home page with   All will need to be styled with css, but works like a charm Tony Posted: September 5 2008 | top | # 11  nikefido Total Posts: 481 Joined: 2008-07-11 New Haven, CT You might be interested in a few tutorials I’ve written 1) Adding or removing callouts in the right/left column: http://www.getfido.net/blog/magento/moving-removing-callouts-on-the-left-right-columns.php 2) Editing the Magento navigation http://www.getfido.net/blog/magento/editing-the-navigation.php This 2nd one will show you how magento retrieves the categories and displays them (and sub categories) for the main navigation and the layered land hand navigation. As for your original problem of categories not showing up, I assume you meant that no matter what settings you did, you couldn’t get the main navigation to appear? Edit: After reading your posts more thoroughly, I can see that you probably don’t need to read my posts to help you as you’ve identified the files you need for your customization. My only suggestion then is to move your changes out of the core code. You can easily do this by duplicating the folder structure in your LOCAL folder and adding the files you edited. So if you edit: app/code/core/Mage/Catalog/Block/Product/View.php you can save your edited version to override the original View.php here: app/code/local/Mage/Catalog/Block/Product/View.php The suggested way of doing this is to overwrite the Block via your own custom module. (There are many threads along this topic) Posted: September 5 2008 | top | # 12  den_piero Total Posts: 9 Joined: 2008-09-14 Jakarta, Indonesia Star Gumbo.....Nothing happen! is it must be styled first with css, so the sub categories can display? or something wrong Posted: October 10 2008 | top | # 13  squirrels Total Posts: 93 Joined: 2008-08-27 Wow, thank you so much for this! Have been trying the entire day to make layered navigation turn up on the front page but without luck… Now at least I can have the Categories on the frontpage! Does anyone have an idea how to make all attributes show up as well? (My goal is still to have a proper layered navigation on the frontpage without having to make a core hack) Posted: October 15 2008 | top | # 14  squirrels Total Posts: 93 Joined: 2008-08-27 @jhutton jhutton - 04 September 2008 09:18 AMRob, Big thanks, dude. I was trying to get my subcategories to show up during product views, and I couldn’t figure out why$category->getChildren() wasn’t returning anything. Now in my view I just do: etc, case anybody is interested. Don’t even have to hack the core. But in what file do you do it? There are several view.phtml and being quite new at this I can’t identify which one you are referring to… Very curious at the output of this! Posted: October 15 2008  |  top  |  # 15