I have a some question about Magento cms static block showing on the custom page.
For example, I have 3 static block (block 1, block 2, block 3) and I need to display block 1 at the Category 1 and subcategories 1, block 2 at the Category 2 and subcategories 2, and block 3 at other pages (home, about, etc)
I try to use Mage::app()->getFrontController()->getRequest()->getRequestUri()
But I received request like "category1.html" and if we going to subcategory of this category - block is changed to default.
If use Mage::app()->getFrontController()->getRequest() I received "catalog/category/view/id/id_number"
I really don't understand how to solve this issue.
Thanks for answer!
You can add a block to a specific part of the page, for a specific category using the Custom Layout Update functionality.
NOTE: If you have a custom theme, the reference name for the footer could be different. This method has been tested to work on the Modern theme included with Magento
Go to Catalog > Manage Categories
Choose the category you want to assign your block to.
Go to the Custom Design tab.
Set Use Parent Category Settings to No
In the Custom Layout Update, insert the following XML
<reference name="bottom.container">
<block type="cms/block" name="my_footer_block">
<action method="setBlockId">
<block_id>my_footer_block</block_id>
</action>
</block>
</reference>
Replace my_footer_block with the Identifier (block_id) of your static block.
Clear your Magento Caches under System > Cache Management and refresh the Category page.
If this does not work, the reference name may not be correct for the theme you are using. You can check the reference name by looking under app/design/frontend/[THEME PARENT]/[THEME CHILD]/layout/page.xml and searching for page/html_footer within the file.
In the file, you will find something like this:
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml">
<block type="page/html_wrapper" name="bottom.container" as="bottomContainer" translate="label">
<label>Page Footer</label>
<action method="setElementClass"><value>bottom-container</value></action>
</block>
<block type="page/template_links" name="footer_links" as="footer_links" template="page/template/links.phtml"/>
<block type="page/switch" name="store_switcher" as="store_switcher" template="page/switch/stores.phtml"/>
</block>
<block type="core/text_list" name="before_body_end" as="before_body_end" translate="label">
<label>Page Bottom</label>
</block>
</block>
Note the name attribute for the page/html_wrapper block. This is the name references used in the code provided in step Step 5. If it's different than bottom.container, change bottom.container to match what is in your page.xml file.
this might help you
Strategy : Check current page is whether current category is available on current page or not, If available then you can check it's level and depending on that you can show you block
Solution :
$_current_category=$this->getCurrentCategory();
1)get current category and if category not available then show default block
2)if category found get it's level $_current_category->getLevel() and then you can place your block accordingly
Override catalog.xml in you local module
Add in
in content reference
in you catalog/category/voew.phtml
add this code
$_current_category=$this->getCurrentCategory();
if(cond == '1st category') {
echo $this->getChildHtml('block1');
}
Similarly for other blocks
You can simply assign a static block to specific categories using the built in functionality Magento provides.
Go to Catalog > Manage Categories
Click the category you want to assign the block to on the left.
Go to the Display Settings tab
Set Display Mode to either Static block only or Static block with products.
Set CMS Block to the static block you want to display on this category.
Click the Save Category button.
Repeat this step for different categories. You can choose a unique static block, or assign the same one to multiple categories this way.
Related
I have created a mega menu group. but i stuck at relating it to file.
All i can see form a default one is
<block type="core/text_list" name="megamenu_left" as="megamenu_left" translate="label">
<label>Left Megamenu</label>
</block>
In Home page(Backend > Design Section):
<reference name="megamenu_left">
<block type="megamenu/list" name="megamenu.list.theme" as="megaMenuLeft" template="sm/megamenu/megamenu-left.phtml">
<action method="setConfig">
<values>
<group_id>2</group_id>
<theme>2</theme>
</values>
</action>
</block>
</reference>
And in home page Front view:
<?php echo $this->getChildHtml('megamenu_left') ?>
Things i didn't get is name="megamenu.list.theme" and how this is rendering.
EDITED
how is 'megamenu_left' from xml above is linked with a menu group i created on the backend. The menu group i created on backend just have a name and 'enable/disable' option.
I'm not sure if I understand the question correctly, but the second XML bit is going to look for the reference "megamenu_left" found in the first XML part, and insert the block at that position.
The block itself has the full name "megamenu.list.theme" in the layout, with the optional shortname "megaMenuLeft". It will render the template file "sm/megamenu/megamenu-left.phtml" which will be positioned in the active theme folder such as "app/design/frontend/theme/..".
The template will be using the PHP block from module "megamenu/Block/List.php" so any $this->functionName() calls or variables accessed from within the function comes from that block.
The frontpage will load the block by name from the first part of XML, which in turn will get the content from the second part XML since it's a reference, meaning it will insert itself in the first XML.
Before posting this, i have looked in to the following, but all of them did not helped me and i was not able to add the block.
magento - adding and positioning a block using local.xml
Magento - Add phtml file to layout block
Magento 1.7:Show category image on category page in full width in a 2 column template
I want to add the category image on top of the page. Currently it is displayed under the product list view, and i want it to be above the left navigation, so that it takes full page width.
I created a template file in mytheme/template/catalog/category/image.phtml and i just added some text "I am here".
After that i add the following xml to my local.xml file under catalog_category_default
<reference name="content">
<block type="catalog/category_view" name="category.image" template="catalog/category/image.phtml"></block>
</reference>
But it is still not working and the text is not displayed there. When this text is displayed, then i will display the category image, but for now i just want to make the block working and display it on top of the page.
Thank you
Maybe your category does not load the layout handle catalog_category_default. There are 2 handles for categories _default and _layered.
To make sure you cover both cases and so you won't duplicate markup try this approach.
define your custom handle.
<my_awsome_category_handle>
<reference name="content">
<block type="catalog/category_view" name="category.image" template="catalog/category/image.phtml"></block>
</reference>
</my_awsome_category_handle>
Then include that handle in both category handles.
<catalog_category_default>
<update handle="my_awsome_category_handle" />
</catalog_category_default>
<catalog_category_layered>
<update handle="my_awsome_category_handle" />
</catalog_category_layered>
Can't find a solution for this issue running Magento 1.7. The category shown above in the main column. I want to show it above both columns, on page width. Here is an example: http://www.vimodos.nl/schoenen?art_sex=92
Anyone with a solution?
Your reply is much appreciated!
UPDATE
Thanks for the reply. I followed your instructions and added a block called category.image in the catalog.xml
<reference name="content">
<block type="catalog/category_view" name="category.products" template="catalog/category/view.phtml">
<block type="catalog/product_list" name="product_list" template="catalog/product/list.phtml">
<block type="catalog/category_image" name="category.image" template="catalog/category/image.phtml">
<block type="catalog/product_list_toolbar" name="product_list_toolbar" template="catalog/product/list/toolbar.phtml">
<block type="page/html_pager" name="product_list_toolbar_pager"/>
After that I created a image.phtml file under /template/catalog/category/
When reloading the category page it's empty, there is no error message. The widgets in the left side bar are visible.
Any suggestions? Many thanks!
This seems to be a built in feature in Magento.
To enable it do the following:
Log in to the admin panel
Go to catalog->manage categories
Select the category you want to add an image
You will see a place where you can add an image (just upload it)
Once you add an image it will automatically show in category page
Update
Here is the code to get the category image:
$category = Mage::getModel('catalog/category')->load($catId);
$category->getImageUrl(); // remember to echo it out
In order to set this up above layered navigation, do the following steps:
Add a block to the catalog.xml (in the: <catalog_category_default translate="label"> section.
Add the code above to the template file (that you referenced in the block above)
Let us know if you need further assistance with this
I've looked for literally over an hour and cannot find an answer to a seemingly simple task. I want to add links to a custom menu that link to pages within Magento, as opposed to a category page.
Does anyone have an answer?
Thanks in advance.
Do you want it to automatically generate the page links?
If not you could just use a static block to create your menu, and then add the block to your layout.
1) Create a new static block with name: left_menu andd add the HTML to the static block.
2) Add this layout update to show the block in the left column:
<reference name="left">
<block type="cms/block" name="left_menu_block" before="-">
<action method="setBlockId"><block_id>left_menu</block_id></action>
</block>
</reference>
In my site home page, I have three blocks like Recommend product,Top ten product and Talking about product, All products are coming properly by their attribute name.For this, I create three attribute in admin section and add layout design in home page in admin section and add block type in page.xml and i call this blocks by their name in 2column-left.phtml
echo $this->getChilidHtml("block_names")
But,My problem is when i click on any product it will redirect to product details page that is catlog/product/view.phtml, on this page i want to add two different blocks as like home page ,I found its xml page also , I think that is catalog.xml on this page make changes in side the content reference and it is coming ,but i want to add a new block as line content , i was trying but i am not getting any idea please any solution for this.
<catalog_category_layered>
<reference name="recommend">
<block type="catalog/product_list" name="catalog.product_list" as="recommend_list" template="catalog/product/view/recommend.phtml">
</block>
</reference>
</catalog_category_layered>
I add above line code in catalog.xml as a new block and call it in view.phtml as echo $this->getChildHtml('recommend') but it is not showing,I am sure this approach is wrong one .
any solution for this how can i call.
Thanks & Regards
Try this,In your catalog.xml
<catalog_product_view translate="label">// find this line
<reference name="content">
..............
<block type="catalog/product_view" name="product.info" template="catalog/product/view.phtml">
<block type="catalog/product_list" name="catalog.product_list" as="recommend_list" template="catalog/product/view/recommend.phtml"/> //add your block into product.info block
.............
</block>
</reference>
................
</catalog_product_view>
call the your block using name in in catalog/product/view.phtml
echo $this->getChildHtml('recommend_list')
Hope this helps