Magento WordPress Integration Magento WordPress Integration

Layout XML, Handles & Changing Templates

Layout handles are a great way to modify your page layout for each different request. The Magento WordPress Integration extension sets different handles depending on the specifics of each request to make things like changing templates quite easy. The code below can go in any of your layout XML files, although it is recommended that you add it to your local.xml file in your custom theme. After making a layout change, if you have your Layout XML cache enabled, you will need to refresh this cache before the change takes place.

Every WordPress Page/Section

<!--
	/**
     * This sets the default template for all blog pages
     * This can be overwritten by more specific layout handles (see below)
     */
    -->
	<wordpress_default>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
	</wordpress_default>

Any Single Post

<!--
	/**
     * This works for all post types, including custom posts (except pages)
     */
    -->
	<wordpress_post_view>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
		<reference name="wp.post.view">
			<action method="setTemplate">
				<template>wordpress/post/view.phtml</template>
			</action>
		</reference>
	</wordpress_post_view>

Single Post by ID

<!--
	/**
     * Change the number '4' for the ID of the post you wish to target
     * This also works with custom post types
     */
    -->
	<wordpress_post_view_4>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
		<reference name="wp.post.view">
			<action method="setTemplate">
				<template>wordpress/post/view.phtml</template>
			</action>
		</reference>
	</wordpress_post_view_4>

Single Post by Post Type

This code will only work if you have the Post Types & Taxonomies add-on extension installed.

<!--
	/**
     * Change the 'article' part for the custom post type you want to target
     */
    -->
	<wordpress_article_view>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
		<reference name="wp.post.view">
			<action method="setTemplate">
				<template>wordpress/post/view.phtml</template>
			</action>
		</reference>
	</wordpress_article_view>

Any Single Page

<wordpress_page_view>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
		<reference name="wp.post.view">
			<action method="setTemplate">
				<template>wordpress/page/view.phtml</template>
			</action>
		</reference>
	</wordpress_page_view>

Single Page by ID

<!--
	/**
     * Change the number '4' for the ID of the page you wish to target
     */
    -->
	<wordpress_page_view_4>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
		<reference name="wp.post.view">
			<action method="setTemplate">
				<template>wordpress/page/view.phtml</template>
			</action>
		</reference>
	</wordpress_page_view_4>

Pages with a Specific Parent

<!--
	/**
     * Change the number '4' for the ID of the page's parent you wish to target
     */
    -->
	<wordpress_page_view_parent_4>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
		<reference name="wp.post.view">
			<action method="setTemplate">
				<template>wordpress/page/view.phtml</template>
			</action>
		</reference>
	</wordpress_page_view_parent_4>

All Post Archives

<wordpress_post_list>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
		<reference name="wordpress_post_list">
			<action method="setTemplate">
				<template>wordpress/post/list.phtml</template>
			</action>
			<action method="setPostRendererTemplate">
				<template>wordpress/post/list/renderer/default.phtml</template>
			</action>
		</reference>
	</wordpress_post_list>

Post Archive on Blog Homepage

<wordpress_homepage>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
		<reference name="wordpress_post_list">
			<action method="setTemplate">
				<template>wordpress/post/list.phtml</template>
			</action>
			<action method="setPostRendererTemplate">
				<template>wordpress/post/list/renderer/default.phtml</template>
			</action>
		</reference>
	</wordpress_homepage>

Category Archives

<wordpress_category_view>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
		<reference name="wordpress_post_list">
			<action method="setTemplate">
				<template>wordpress/post/list.phtml</template>
			</action>
			<action method="setPostRendererTemplate">
				<template>wordpress/post/list/renderer/default.phtml</template>
			</action>
		</reference>
	</wordpress_category_view>

Category Archive by Category ID

<!--
	/**
     * Change the number '4' for the ID of the category you wish to target
     */
    -->
	<wordpress_category_view_4>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
		<reference name="wordpress_post_list">
			<action method="setTemplate">
				<template>wordpress/post/list.phtml</template>
			</action>
			<action method="setPostRendererTemplate">
				<template>wordpress/post/list/renderer/default.phtml</template>
			</action>
		</reference>
	</wordpress_category_view_4>

Post Archive by Post Type

This code will only work if you have the Post Types & Taxonomies add-on extension installed.

<!--
	/**
     * Change the 'article' for the post type who's archive you want to target
     */
    -->
	<wordpress_article_list>
		<reference name="root">
			<action method="setTemplate">
				<template>page/1column.phtml</template>
			</action>
		</reference>
		<reference name="wordpress_post_list">
			<action method="setTemplate">
				<template>wordpress/post/list.phtml</template>
			</action>
			<action method="setPostRendererTemplate">
				<template>wordpress/post/list/renderer/default.phtml</template>
			</action>
		</reference>
	</wordpress_article_list>
Post your comment

FishPig Ltd