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
How to show specific category on home page
 
buffalokill
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2007-12-12
Coeur d'Alene, Idaho
 

Hi Guys,

I’ve been using this nifty code on my homepage to show the root category on the homepage:

{{block type="catalog/product_list" show_root_category="true"}}

Is there a way to rewrite this so that it shows a specific category?

Say I made a “featured products” category, so I would just add the products to it, to have them shown on the home page.

Thanks for any help!

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

You can use

{{block type="catalog/product_list" category_id="123"}}
where 123 is your featured category id

 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
 
buffalokill
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2007-12-12
Coeur d'Alene, Idaho
 

excellent smithers. thanks.

um. whats the easy way to find out the category’s ID? I dont see it under manage categories.

so, am i able to hide the featured category from showing in the main navigation, but still have any products show up when i insert that code?

 
Magento Community Magento Community
Magento Community
Magento Community
 
gchalk
Jr. Member
 
Total Posts:  1
Joined:  2007-12-14
 

How do you add more than one category to the home page? for instance I would like to add a featured, sale, and new category.

if I put more than one line from above, I get error messages.

 
Magento Community Magento Community
Magento Community
Magento Community
 
buffalokill
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2007-12-12
Coeur d'Alene, Idaho
 
gchalk - 15 December 2007 06:47 AM

How do you add more than one category to the home page? for instance I would like to add a featured, sale, and new category.

if I put more than one line from above, I get error messages.

show me the bit of code you are using to call multiple categories.

I would assume something like this would show categories 1, 2 and 3.

{{block type="catalog/product_list" category_id="1,2,3"}}

also - how did you go about finding the category ID’s?

 
Magento Community Magento Community
Magento Community
Magento Community
 
buffalokill
Jr. Member
 
Avatar
Total Posts:  15
Joined:  2007-12-12
Coeur d'Alene, Idaho
 

Anyone have an answer on how to find a category ID?

Is it possible to go off of a category name instead of ID?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Michael
Magento Team
 
Total Posts:  684
Joined:  2007-08-31
 
buffalokill - 17 December 2007 02:43 PM

Anyone have an answer on how to find a category ID?

Is it possible to go off of a category name instead of ID?

Hi buffalokill,

You can see the category id in the URL while editing it in the admin. E.g. http://demo-admin.magentocommerce.com/admin/catalog_category/edit/id/4/

 
Magento Community Magento Community
Magento Community
Magento Community
 
Electric-dsctc
Member
 
Avatar
Total Posts:  35
Joined:  2008-01-21
 

Hi there,
I’m trying to use the same “{{block type="catalog/product_list" category_id="10"}}" thing but not on a cms page , on a template

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

@Electric-dsctc: If you wish to create a block directly from template you do it like this:

<?=$this->getLayout()->createBlock('catalog/product_list')->setCategoryId(10)->toHtml()?>

 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
 
Electric-dsctc
Member
 
Avatar
Total Posts:  35
Joined:  2008-01-21
 

Hi moshe..
I’ve tried the code you suggested but it returned some errors…
I’m missing something really simple right?  tongue rolleye

exception ‘Mage_Core_Exception’ with message ‘Block with name “product_list.toolbar” already exists’ in /home/pablo/workspace/magento/app/Mage.php:371

I’ve attached the hole error thing (didn’t want to spit it out here ...)

thanks for your patience

File Attachments
error.log  (File Size: 3KB - Downloads: 29)
 
Magento Community Magento Community
Magento Community
Magento Community
 
Electric-dsctc
Member
 
Avatar
Total Posts:  35
Joined:  2008-01-21
 

Anyone have try this and worked ? I don’t know what I’m doing wrong..but can’t seem to work it out…
Thanks

 
Magento Community Magento Community
Magento Community
Magento Community
 
mr_dimsum
Member
 
Avatar
Total Posts:  35
Joined:  2008-01-28
 

Moshe,

Say if I created two categories, “Featured” & “New”.. If I use the following code you provided: {{block type="catalog/product_list" category_id="123"}}, would this theoretically function the way I would want it to? I haven’t tinkered around with Magento enough to truly know, as I’m slowly studying the kinks of the screencasts and guides provided, but when I think about it, it seems to make sense.

Featured and New would be its own proprietary categories and since a product can appear in multiple categories at once, this would surely solve the problem. Is the sorting order of products, by default, displayed from newest to oldest? If not, how must one get this sort order to be achieve by default?

 
Magento Community Magento Community
Magento Community
Magento Community
 
Spek
Member
 
Total Posts:  62
Joined:  2007-11-28
 
Moshe - 14 December 2007 12:42 PM

You can use

{{block type="catalog/product_list" category_id="123"}}
where 123 is your featured category id

We have 4 or 6 products “in the spotlight” on our home page (in a grid) which are manually added to a specific category to show up here, below that is a list of new products (in a list), these are shown automatically based on their id/time. The attachment shows an example.

Is there an easy way to exclude a category with the same code? That way our “spotlight” category doesn’t show up in the new products list and we don’t have to worry about adding new products to a seperate list each day.

And how do we use that piece of code twice without it throwing errors?  grin

Image Attachments
layout_narrow_content_blurred.jpg
 
Magento Community Magento Community
Magento Community
Magento Community
 
mr_dimsum
Member
 
Avatar
Total Posts:  35
Joined:  2008-01-28
 

Ben,

How abouts were you able to modify the new products to show up based on their id/time?

 
Magento Community Magento Community
Magento Community
Magento Community
 
lgp
Jr. Member
 
Total Posts:  4
Joined:  2008-02-14
 
Electric-dsctc - 25 January 2008 06:24 AM

Hi moshe..
I’ve tried the code you suggested but it returned some errors…
I’m missing something really simple right?  tongue rolleye

exception ‘Mage_Core_Exception’ with message ‘Block with name “product_list.toolbar” already exists’ in /home/pablo/workspace/magento/app/Mage.php:371

I’ve attached the hole error thing (didn’t want to spit it out here ...)


thanks for your patience

I am facing a similar issue. I added the following code to my Home page {{block type="catalog/product_list" category_id="4"}} and it works fine. Now what I want to do is add another listing of “Featured products” category to the sidebar. So I tried in my template to add something like:

$this->getLayout()->createBlock('catalog/product_list')->setCategoryId(4)->toHtml()

But I get the following exception.

exception ‘Mage_Core_Exception’ with message ‘Block with name “1203337198” already exists’ in C:\wamp\www\lojatilla\app\Mage.php:346
Stack trace:
#0 C:\wamp\www\lojatilla\app\code\core\Mage\Core\Model\Layout.php(354): Mage::throwException(’Block with name...’)
#1 C:\wamp\www\lojatilla\app\code\core\Mage\Catalog\Block\Product\List.php(100): Mage_Core_Model_Layout->createBlock(’catalog/product...’, 1203337198)

Any ideas?

 
Magento Community Magento Community
Magento Community
Magento Community
 
lgp
Jr. Member
 
Total Posts:  4
Joined:  2008-02-14
 

Well I think I found it out.

When converting toHtml the Product List block, the class creates a new Toolbar block:

$toolbar $this->getLayout()->createBlock('catalog/product_list_toolbar'time());

So the problem when we want to have two product lists in the same page (for example, a listing in the home’s content, and other in a sidebar) is that if the toolbar block is created in the same second, it will crash (in core\model\Layout.php):

elseif (isset($this->_blocks[$name])) {
  Mage
::throwException(Mage::helper('core')->__('Block with name "%s" already exists'$name));
}

So what I did is a simple change in Block\Product\List.php in line 100:

$toolbar $this->getLayout()->createBlock('catalog/product_list_toolbar'microtime());
That way, we know that the toolbar block name will be different each time it gets created. I have just submitted a bug report with this.

Hope it helps.

 
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
52215 users|863 users currently online|105481 forum posts