Magento Layot XML - Change template for 2columns-left.phtml - php

I'm working on a Magento project which is based on the Ultimo theme and is using the fishpig wordpress extension.
I'm trying to change the 2columns-left.phtml template on the wordpress pages only but can't get it working!
To explain the scenario further:
The Ultimo theme set's the main content before the left column and uses a float: right; css rule on the main content to position it after the left column. The HTML is structured like this:
<div class="col-main grid4-3 grid-col2-main in-col2">
[omitted code]
</div>
<div class="col-left sidebar grid4-1 grid-col2-sidebar in-sidebar"><div class="wp-sidebar">
[omitted code]
</div></div>
This HTML is being generated by ultimo/default/template/page/2columns-left.phtml with:
<div class="col-main grid4-3 grid-col2-main in-col2">
<?php echo $this->getChildHtml('global_messages') ?>
<?php echo $this->getChildHtml('content') ?>
</div>
<div class="col-left sidebar grid4-1 grid-col2-sidebar in-sidebar"><?php echo $this->getChildHtml('left') ?></div>
I would like to use my own template file to position the sidebar before the main content in the HTML for the wordpress pages only, this way the wordpress categories will stack above the main content in a mobile.
I've tried creating my own template called page/wp-2columns-left.phtml and setting it for the Wordpress section of the site with the below code and a few other variations in my themes local.xml:
<wordpress_default>
<reference name="root">
<action method="setTemplate"><template>page/wp-2columns-left.phtml</template></action>
</reference>
</wordpress_default>
But still the origional 2columns-left.phtml template is being called. I could edit the template file directly and get the desired result on the WordPress section of the site but that would affect the rest of the Magento site and is not good practice.

You can achieve this using XML layout code. The following code will change the template for all pages created in WordPress:
<wordpress_page_view>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-left.phtml</template>
</action>
</reference>
</wordpress_page_view>
The following code will change the template for the WordPress page with an ID of 32:
<wordpress_page_view_32>
<reference name="root">
<action method="setTemplate">
<template>page/2columns-left.phtml</template>
</action>
</reference>
</wordpress_page_view_32>
After adding this code to an XML layout file, you will need to refresh your Layout XML cache (if it's enabled).

Related

How can I add a unique second static block to every category page at the bottom? with magento

I want to add a second static block to the bottom of every category page in my magento 1.9 store.
Like this site
I want a description on top of the products but also a larger description at the bottom.
I am very familiar with magento and hard coding but it seems I get stuck here. I search the web for ours but no solution.
I could manage it to get a static block at the footer but then on every page it is the same text and I want different text at each category.
You can do this through layout.xml. To add a static block simply add:
<block type="cms/block" name="block_key">
<action method="setBlockId">
<block_id>block_key</block_id>
</action>
</block>
to the content node on the category section. Then you can call it via:
<?php echo $this->getChildHtml('block_key'); ?>
where ever you would like in your template.
To add custom text you can use the magic set method which you will add to the custom design section on the category page.
<reference name="block_key">
<action method="setCustomText">
<text>This is my custom text</text>
</action>
</reference>
Then within your template/block you can get this from using the following :
<?php echo $this->getCustomText(); ?>
Let me know if this works for you.

To call a block in magento home page static block

I want to call a block in content of home page. I am writing a code like that:
{{block type='blog/menu_sidebar' template='latest_blog/latest-blog.phtml'}}
But phtml file is not coming in home page.
On the other hand when I call block in layout update xml under under the design tab by writing the code like that :
<block type="blog/menu_sidebar" name="right.blog">
<action method="setTemplate" >
<template>latest_blog/latest-blog.phtml</template>
</action>
<block type="blog/tags" name="blog_tags" />
</block>
Then the phtml file is coming in home page.
My problem is that i want to include latest-blog.phtml file in the content of home page because I will have to play with the div structure for designing which i can not play in the layout section.
You can use getLayout() function
<?php echo $this->getLayout()
->createBlock("blog/menu_sidebar")
->setTemplate("latest_blog/latest-blog.phtml")
->toHtml(); ?>
This way u can load. if you have any option you can set by calling
->setCustomOption($optionValue)

call a phtml file in Layout Update XML to set title in magento [duplicate]

In Magento how to call a phtml file in cms page to set page title which title I set in my phtml file? I am using
$this->getLayout()->getBlock('head')->setTitle('your title');
to set page title.
To call a phtml file in a cms page or cms static block:
{{block type="core/template" template="templateFolder/your_template.phtml"}}
If you know, where the block file(php file) for your phtml file resides, then you can use it as type.
Example: Suppose you want to call new.phtml file that resides in catalog/product folder, and you know that its corresponding Block file(php file) resides in Catalog/Product folder, then you can use:
{{block type="catalog/product" template="catalog/product/new.phtml"}}
More reading: here
Hope this helps!
You cannot change the title of the page from a template file when using it in a cms block or cms page because the head block is already rendered when the page (or block) content is parsed.
It's not possible to change page title from phtml file of cms pages as already told by #Marius
you need to add to it's design in cms page as given below :
<reference name="head">
<action method="setCustomTitle" translate="title"> <title> Custom Title </title> </action>
</reference>
Add the below XML piece under CMS > Pages > Manage Content > Select a specific CMS Page
Navigate to "Design" tab > Layout Update XML >
<reference name="head">
<action method="setCustomTitle" translate="title"> <title> Custom Title </title> </action>
</reference>
Make sure the CACHE folders are DELETED under below:
{Root Magento Folder}/var/cache
{Root Magento Folder}/var/full_page_cache
Hope this helps!
Happy Coding...

How to call a phtml file in cms page to set page title

In Magento how to call a phtml file in cms page to set page title which title I set in my phtml file? I am using
$this->getLayout()->getBlock('head')->setTitle('your title');
to set page title.
To call a phtml file in a cms page or cms static block:
{{block type="core/template" template="templateFolder/your_template.phtml"}}
If you know, where the block file(php file) for your phtml file resides, then you can use it as type.
Example: Suppose you want to call new.phtml file that resides in catalog/product folder, and you know that its corresponding Block file(php file) resides in Catalog/Product folder, then you can use:
{{block type="catalog/product" template="catalog/product/new.phtml"}}
More reading: here
Hope this helps!
You cannot change the title of the page from a template file when using it in a cms block or cms page because the head block is already rendered when the page (or block) content is parsed.
It's not possible to change page title from phtml file of cms pages as already told by #Marius
you need to add to it's design in cms page as given below :
<reference name="head">
<action method="setCustomTitle" translate="title"> <title> Custom Title </title> </action>
</reference>
Add the below XML piece under CMS > Pages > Manage Content > Select a specific CMS Page
Navigate to "Design" tab > Layout Update XML >
<reference name="head">
<action method="setCustomTitle" translate="title"> <title> Custom Title </title> </action>
</reference>
Make sure the CACHE folders are DELETED under below:
{Root Magento Folder}/var/cache
{Root Magento Folder}/var/full_page_cache
Hope this helps!
Happy Coding...

show magento layer state on catalog listing (not on sidebar)

Is there a way I could load filter layer state on the content area just below the page title
I've tried several ways like including template/catalog/layer/state.phtml into template/catalog/product/list.phtml, adding below snippet on <reference name="content"> on catalog.xml
<block type="catalog/layer_view" name="catalog.leftnav" after="leftnav" template="catalog/layer/view.phtml"/>
nothing works... what should I do?
thanks before :)
Here is quick fix: paste this in catalog/product/list.phtml
<?php echo $this->getLayout()->createBlock('catalog/layer_state')->setTemplate('catalog/layer/state.phtml')->toHtml(); ?>
In page.xml search <block type="core/text_list" name="content" as="content" translate="label">:
Paste this code here (drawback: it will load in every content, will be better to find putting it within catalog pages block tag):
<block type="catalog/layer_state" name="catalog.layer.state" as="catalog.layer.state" template="catalog/layer/state.phtml"/>
Now incatalog/product/list.phtml file you can get this by:
<?php echo $this->getChildHtml('catalog.layer.state') ?>

Categories