catalog/category/homepage_view.phtml contains: (this is my template for
how I want the category to display on the homepage. I also have a
view.phtml that is used for all sub categories)
If you were to simply add the first block to the default.xml page
you got an error (something like it didn’t know what category was) This
error also stops you displaying the category title, image and
description onto the front page of the site (which means you would have
to us CMS blocks of the CONTENT section on the page editor; neither of
which are very nice!)
The error appears to originate from the getCurrentCategory()
function in app\code\core\Mage\Catalog\Block\Category\View.php
folder. It doesn’t seem to get the category object when it is at
root level. At all other levels it appeared to work fine. So I
added a check to see if the cateogry object was blank and then get the
category object from the root category ID.
public function getCurrentCategory() { $_currentCategory = Mage::registry('current_category');
This allows you to put category details and products onto the
homepage.... I know it’s not an ideal solution to bestselling but it’s
better than having to modify the HTML in a text area!!!
So
this would change what shows on home page ? or am i not reading it
right. If so what files should i change and remove what out of them ?
I am just trying myself to add content to my home page without
having to manually ass stuff each time i want to change it. Would like
it to auto pull stuff from my catalog. So is that code something i have
to add to my home page? sorry i am new to most of it but have been
trying hard to learn
Yes,
this change allows you to add a block to the homepage that will show
the home category details as well as allowing you to show the products
included in that category. Using this method you have much simpler
control over displaying products on the front page than with the
included example (which uses hardcoded data stored in the database as
discussed in other topics)
If you add products to the root cateogry they don’t show in the
shop, this is because there is no catalog/category or product block on
the front page; it gets added as you drill down by the
app\design\frontend\OC\default\layout\catalog\category\default.xml page
(again substitute OC with your template or default). You can’t just add
the block to the front page as it causes an error. The steps below show
how to add the block to the template and then make the change to allow
the functionality to work.
To make this change you need to do the following:
1) Open \app\design\frontend\OC\default\layout\core\default.xml (change OC to your template name or default)
2) Under the line : <block type="core/text_list" name="content" as="content"/> add
This will use the same view.phtml layout as you get when
you drill down into the categories… if you want a custom template for
the homepage you need to copy this file and change the filename above
to match the new file. (Open this file and have a look at how it
displays data and modify it as required)
3) Make the change to getCurrentCategory() so that the category object is avaliable on the front of the site
4) Go to admin, add a title, description and image to the root
category as required. Add products to root category and they will
appear on the home page.
Ok i added
<block type="catalog/category_view" name="category.products">
<action method="setTemplate"><template>catalog/category/view.phtml</template></action>
</block>
to the \app\design\frontend\default\default\layout\core\default.xml
and added if (isset($_currentCategory)){
return Mage::registry(’current_category’);
} else {
$categoryId = Mage::getSingleton(’core/store’)->getConfig(’catalog/category/root_id’);
$category = Mage::getModel(’catalog/category’)->load($categoryId);
Mage::register(’current_category’, $category);
return Mage::registry(’current_category’);
}
to the app\code\core\Mage\Catalog\Block\Category\View.php
and finally got it to go with no error’s and then added a title,
description and image to the root category then added products to the
root catalog but nothing shows up on the homepage.. Did i miss
something ?
and then add something like this into your template file
<div id="bestsellers"> <h4>Bestsellers</h4> <p>Duis eget erat eu nulla interdum sagittis.</p> <!-- [start] content --> <?=$this->getChildHtml('category.productlist')?> <!-- [end] content --> </div>
Once again you can change this file catalog/product/list.phtml to a
custom version for the homepage and change the name of the file you use
here. This list.phtml displays product images etc and I decided I
only wanted product names so I made the following file:
<?$_productCollection=$this->getLoadedProductCollection()?> <?if(!$_productCollection->getSize()):?> <div class="note-msg"> <?=__('There are no products matching the selection.')?> </div> <?else:?> <ul> <?foreach ($_productCollection as $_product):?> <li><a href="<?=$_product->getProductUrl()?>" title="<?=$this->htmlEscape($_product->getName())?>"><?=$_product->getName()?></a></li> <?endforeach;?> </ul> <?endif;?>
Thanks for the tip dan but i also could not get it to work.
I put
<block type="catalog/product_list" name="category.productlist">
<action method="setTemplate"><template>catalog/product/list.phtml</template></action>
</block>
that into default.xml
and
<div id="bestsellers">
<h4>Bestsellers</h4>
<p>Duis eget erat eu nulla interdum sagittis.</p>
<!-- [start] content -->
<?=$this->getChildHtml('category.productlist')?>
<!-- [end] content -->
</div>
into teplate which i hope you meant cms/manage pages then edit the
home page and paste that in there (which i was just going to use the
default list.phtml
was there a line there i was supposed to change in the code also somewhere as of right now it just shows on my homepage
Bestsellers
Duis eget erat eu nulla interdum sagittis.
getChildHtml(’category.productlist’)?>
thx for your help on site also i have learned alot from your posts.
Mmmm.....
I’ve downloaded the new version today and the templating has changed
quite a bit.... I’ve move my site from the old version to the new today
and got all the functionality I added working again. I will post
a URL tomorrow to show how it works and perhaps the complete source
from my machine.
Sorry that the example didn’t work exactly but perhaps it’ll point you in the right direction of what to change.
will
they implement that as part of it later ? it would just be nice to goto
the product page and click the box for root and have it show there.
would make it easy to change the front page with new products.
I dont understand few things. First of all is how to put this piece
of code (and how this code should look like?) into file (witch file?)
to show on homepage output of script php.
and how can I refer from template to this block ?
What is this: “category_view” ? - i dont have this one in my magento folder structure.
I gues above code tells what template must be used.
Does one have to change the list.phtml file or not ?
I can get the default category name and description on the
homepage, but I can see no products, though I put to in the root
category of the store.