How to add different static block to every category - magento

I want to add different static block to every category at some specific places on the page.
how would i do that.????
Reference http://www.partybounty.com
here the blocks in footer and banner are different for every category.

Or you can use Layout Update XML (under custom design tab) on each category which can be controlled from the admin a bit like;
<reference name="content">
<remove name="breadcrumbs" />
<reference name="category.products">
<action method="setPageTitleDisabled"><disabled>1</disabled></action>
</reference>
<block type="page/html_wrapper" name="category.home.left">
<action method="setElementTagName"><value>div</value></action>
<action method="setElementClass"><value>col-left sidebar col3</value></action>
<block type="manufacturers/navigation_left" name="category.home.leftnav" template="manufacturers/navigation/left.phtml"/>
</block>
<remove name="category.description" />
<block type="page/html_wrapper" name="category.home.right" after="category.home.left">
<action method="setElementTagName"><value>div</value></action>
<action method="setElementClass"><value>category-home</value></action>
<block type="core/template" name="category.home.description" template="catalog/category/description.phtml" />
</block>
<block type="catalog/navigation" name="category.home.categories" template="catalog/navigation/categories.phtml" after="category.description">
<action method="setIsMini"><value>1</value></action>
</block>
<block type="homepage/homepagebanner" name="category.home.banner" after="category.home.categories">
<action method="setIsCategory"><value>1</value></action>
</block>
<block type="bestsellers/slider" name="category.home.bestsellers" after="category.home.banner" />
<block type="bundlekits/slider" name="category.home.bundlekits" after="category.home.banner" />
<block type="featuredproducts/listing" name="category.home.featured" after="category.home.bestsellers" />
</reference>
This gives you flexibility for different positioning and including different blocks on a per category basis, downside is it's a little time consuming to setup.

Did you try
Go to Admin Catalog - Manage categories
choose your category
go to Display Mode & choose either static block only or static block & products
go to CMS block & choose the block you have created
See How do I create and edit Static Blocks?
If you want to add the static block to the header/footer you may have to
add a field to your category see http://magecracker.wordpress.com/2012/07/19/how-to-add-custom-fieldattribute-in-magento-category/
then
<?php echo Mage::app()->getLayout()
->createBlock('cms/block')
->setBlockId(Mage::registry('current_category')->getData('block id from custom field'))->toHtml(); ?>

You call following in any category page. You can create different static blocks for each categories and call them depending on requirement or selecting from category edit page
<?php $app = Mage::app(); ?>
<?php echo $app->getLayout()
->createBlock('cms/block')
->setBlockId('your_block_id')->toHtml(); ?>

Related

Magento creating a custom template from backend category layout

I need to create a custom template with products categories. Which means under one category limited number of related products should be displayed. Under another category that category related products should be displayed. Also there should be a label which display those category names. As well as I need to add a link to view more products.
I am doing this through category layout (backend). I added the below code and tried.
<reference name="header">
<block type="core/template" name="header_nav" as="headerNav" template="page/html/headernav.phtml">
</block>
</reference>
<reference name="content">
<block type="catalog/product_list" name="product_list_flowers" template="catalog/product/list.phtml">
<action method="setData"><key>category_id</key><value>178</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
<block type="catalog/product_list" name="product_list_cakes" template="catalog/product/list.phtml">
<action method="setData"><key>category_id</key><value>179</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
</reference>
Category products are displaying. But this is not limiting the number of products. Also the header is not displaying. And I cannot add a link to this page.
Can anyone please help me on this. Thank You.
To be able to set limitation on Product Collection (since this differs from category to category in your case), find below the implementation:
<reference name="content">
<block type="catalog/product_list_flowers" name="product_list_flowers" template="catalog/product/list/flowers.phtml">
<action method="setData"><key>category_id</key><value>178</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
<block type="catalog/product_list_cakes" name="product_list_cakes" template="catalog/product/list/cakes.phtml">
<action method="setData"><key>category_id</key><value>179</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
</reference>
The above code will continue to display 4 columns with products.
Create block files (If this differs from category to category)
app/code/local/Namespace/Module/Block/Catalog/Product/List/Flowers.php
app/code/local/Namespace/Module/Block/Catalog/Product/List/Cakes.php
Override List.php (If all the categories require same limitation of products)
app/code/local/Namespace/Module/Block/Catalog/Product/List.php
 
<reference name="content">
<block type="catalog/product_list" name="product_list_flowers" template="catalog/product/list/flowers.phtml">
<action method="setData"><key>category_id</key><value>178</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
<block type="catalog/product_list" name="product_list_cakes" template="catalog/product/list/cakes.phtml">
<action method="setData"><key>category_id</key><value>179</value></action>
<action method="setColumnCount"><count>4</count></action>
</block>
</reference>
Below line no: 87, In this public function _getProductCollection()
...
$this->_productCollection = $layer->getProductCollection();
$this->_productCollection->setPageSize(10); //this will display only 10 products
...
Let me know if I was able to understand it correctly.
Happy Coding...

how to add custom page layout pages magento

I have custom layout page
I have added the following code to app/code/core/Mega/page/etc/config.xml
<shop_overview module="page" translate="label">
<label>Shop OverView Page</label>
<template>page/shop_overview.phtml</template>
<layout_handle>shop_overview</layout_handle>
</shop_overview>
This show the "Shop Over View Page" on admin panel in page layout drop-down
I want to remove product list from category for this page layout only.
I tried the following but it is not working.
<shop_overview translate="label">
<label>All One-Column Layout Pages</label>
<reference name="root">
<action method="setTemplate">
<template>page/shop_overview.phtml</template>
</action>
<action method="setIsHandle"><applied>1</applied></action>
</reference>
<reference name="category.products">
<remove name="product_list" />
</reference>
</shop_overview>
Instead of this you can assign static block to this category by changing display mode to Static Block Only.
And then creating and selecting that block for that category.
Reference Link: http://leveluptuts.com/tutorials/magento-community-tutorials/19-how-add-static-block-category-page

can't move content block to header Magento

I am new magento. I try to play around structure block and content block. when I try to move "My Cart" block from right side to header section. It doesn't work. but once I move another block it works. ex:
<reference name="header">
<block type="checkout/cart_sidebar" name="cart_sidebar" template="checkout/cart/sidebar.phtml" before="-">
<action method="addItemRender"><type>simple</type><block>checkout/cart_item_renderer</block><template>checkout/cart/sidebar/default.phtml</template></action>
<action method="addItemRender"><type>grouped</type><block>checkout/cart_item_renderer_grouped</block><template>checkout/cart/sidebar/default.phtml</template></action>
<action method="addItemRender"><type>configurable</type><block>checkout/cart_item_renderer_configurable</block><template>checkout/cart/sidebar/default.phtml</template></action>
<block type="core/text_list" name="cart_sidebar.extra_actions" as="extra_actions" translate="label" module="checkout">
<label>Shopping Cart Sidebar Extra Actions</label>
</block>
</block>
</reference>
this's work (it show on top page) but when I change reference to "head", this block just disappear. Please guild me.
here's the screenshot that I want.
http://awesomescreenshot.com/0002ivnb10
You have to render the block manually by:
<?php echo $this->getChildHtml('extra_actions'); ?>
in cart phtml template file
Header, head & cart blocks are not core/text_list blocks means they will not render their children automatically

How to place my custom block inside another block in Magento using layout xml?

first of all I want to say that I have searched for this whole day on te internet and could not find what I wanted. I am a newbie here as well, so please forgive me if I broke any rule.
I am trying to develop a module which will add videos to product page along with images. I am stuck in this concept:
How do I insert my block into an existing base block ? For example, in the product page, there is a block product.info. Inside this block there is "Availability", "Price" etc.
How do I insert my custom block just below "Availability" and above "Prices" using my module's layout xml and template.
So I am trying to achieve something like this using my module's layout file:
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
WRITE BLOCK HERE SO THAT MY BLOCK SHOWS BELOW AVAILABLITY
</reference>
</reference>
</catalog_product_view>
Is this possible ? or Do I have to override the core class Mage_Catalog_Block_Product_View to do this ?
PS: Basically my aim is to list my videos next to images. Right now, I am able to list my videos from module, but images don't come in that case. I used
<block type="myblock/myblock" name="somename" as="media" template="abc.phtml"/>
So I want to append my block to the existing content.
I solved it. I had to rewrite the Mage_Catalog_Block_Product_View_Media .
In my class I over-rid the function _toHtml function like this:
public function _toHtml()
{
$html = parent::_toHtml();
$html.=$this->getChildHtml('media_video');
return $html;
}
where "media_video" is my block. My layout xml file:
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
<reference name="product.info.media">
<block type="myblock/myblock" name="somename" as="media_video" template="beta/abc.phtml"
before="-"/>
</reference>
</reference>
</reference>
</catalog_product_view>
You can add new block instead of over-right existing.
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
<block type="myblock/myblock" name="somename" as="media_new" template="abc.phtml"/>
</reference>
</reference>
</catalog_product_view>
Get New Block using following code in phtml file
<?php echo $this->getChildHtml('media_new') ?>
Thanks
Note output="toHtml" in the below code. This will print your block in product.info section.
<catalog_product_view translate="label">
<reference name="content">
<reference name="product.info">
<block type="myblock/myblock" name="somename" as="media"
template="abc.phtml" output="toHtml" before="-" />
</reference>
</reference>
</catalog_product_view>

Magento: product specfic designs through 'Custom Layout Update'

If I want to control how each product is displayed (i.e. a custom design when specified) my first thought is to do this:
Create a custom view.phtml in template/catalog/product/my_view.phtml
Navigate in the admin to Product->Design->Custom Layout Update
Add this block:
<reference name="content">
<action method="setTemplate">
<template>catalog/product/view_print.phtml</template>
</action>
</reference>
But the template is never loaded, only the default view.phtml. Is this the correct method? I need to be able to do this in the product settings.
Found the answer:
<reference name="product.info">
<action method="setTemplate"><template>catalog/product/NEW_VIEW.phtml</template></action>
</reference>
Navigate in the admin to Product->Design->Custom Layout Update > Add the below custom block. > It works for all the stores.
"<reference name="product.info">
<block type="namespace_modulename/catalog_product_list_custom"
name="catalog.product.modulename" as="modulename" after="tierprices"
template="modulename/catalog/product/modulename.phtml"/>
</reference> "
Add the below code in view.phtml
<?php echo $this->getChildHtml('modulename'); ?>

Resources