简体   繁体   中英

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

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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM