简体   繁体   English

Magento Layot XML-更改2columns-left.phtml的模板

[英]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. 我正在一个基于Ultimo主题并使用fishpig wordpress扩展名的Magento项目。

I'm trying to change the 2columns-left.phtml template on the wordpress pages only but can't get it working! 我正在尝试仅更改wordpress页面上的2columns-left.phtml模板,但无法使其正常工作!

To explain the scenario further: 要进一步解释该方案:

The Ultimo theme set's the main content before the left column and uses a float: right; Ultimo主题集的主要内容在左列之前,并使用float: right; css rule on the main content to position it after the left column. 在主要内容上使用css规则将其定位在左列之后。 The HTML is structured like this: HTML的结构如下:

<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: 该HTML由ultimo / default / template / page / 2columns-left.phtml通过以下方式生成:

<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. 我想使用自己的模板文件将侧边栏仅放在wordpress页面的HTML中的主要内容之前,这样wordpress类别将堆叠在移动设备中主要内容的上方。

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: 我尝试创建自己的名为page / wp-2columns-left.phtml的模板,并使用以下代码和主题local.xml中的其他一些变体将其设置为网站的Wordpress部分

<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. 但是仍然调用原始的2columns-left.phtml模板。 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. 我可以直接编辑模板文件,并在网站的WordPress部分获得所需的结果,但这会影响Magento网站的其余部分,这不是一个好习惯。

You can achieve this using XML layout code. 您可以使用XML布局代码来实现。 The following code will change the template for all pages created in WordPress: 以下代码将更改在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: 以下代码将更改ID为32的WordPress页面模板:

<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). 将此代码添加到XML布局文件后,您将需要刷新Layout XML缓存(如果已启用)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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