Magento Recent WordPress Posts in Magento

Recent WordPress Posts in Magento

Recent WordPress Posts in Magento

Adding a dynamic list of your most recent blog posts to your Magento homepage keeps your homepage refresh and allows your users - and search engines - to get easy access to your blog posts.

Click here for the tutorial that explains how to do this yourself.

If you want an easy life, we can add and style this block for you and put it exactly where you want on your site.

£149.99
Secure Checkout

Recent WordPress Posts in Magento Reviews

Have Your Say...

If you have purchased Recent WordPress Posts in Magento and want to share your opinion, you can leave a review below.

  • Gemma
    I purchased this service and it was complete in under an hour. The block looked just how I imagined it and helps fill out my homepage. I love that it is dynamic and each time I add a new article it is updated automatically. Five stars :)
  • Dan Adams
    I already had a block ready to integrate wordpress into coded into my theme. FishPig incorporated the recent posts block perfectly into my layout.
  • MyNutritionOnline
    Im not a developer so had to get fishpig to do add the recent posts widget for me. They did it really quick and didn't cause any downtime on my site. :)

Displaying Recent WordPress Posts in Magento

With the release of WordPress Integration 2.0 for Magento eCommerce, a new way of adding recent posts to the homepage was introduced. The new way, while different, allows for control of the sidebar widgets via the WordPress Admin interface (WP Admin > Appearances > Widgets). Although at this time it isn't possible to add recent posts to the homepage using this method, it is still simple enough to add them using XML or the {\{block type="..."}} system; let's take a look how...

Adding A List of WordPress Posts to Magento

The code below will add a simple list of your most recent WordPress posts to your Magento homepage.


<reference name="content">
	<block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" as="recent_posts" template="wordpress/sidebar/widget/posts.phtml">
		<action method="setTitle"><title>Latest Posts</title></action>
		<action method="setPostCount"><post_count>5</post_count></action>
	</block>
</reference>

Let's take a look at what the above code actually does...

Line 1: This line sets the block reference, which effectively positions the block in your site. For this example, we have told Magento to display our block in the content block, which is the main content area of the page.

Line 2: Firstly this line sets the block type, in this case wordpress/sidebar_widget_posts. This is the block type that will load in your recent posts (to see what other widget blocks are available, take a look in app/code/community/Fishpig/Wordpress/Block/Sidebar/Widget/). The next parameters are name and as. These two parameters name the block and provide tokens with which you can refer to the block from your XML and PHP code. The last parameter on this line, template, allows you to set the template of the block. For this block, we have used the default template, however, if you wanted, you could create a custom template and refer to that using this parameter.

Line 3: Here we set the title of the block. Feel free to change the 'Latest Posts' text to anything you want.

Line 4: Here we set the number of posts that we want to display. The code above instructs Magento to display the latest 5 published posts but you can set it to any number you wish.

Line 5: This line closes the block tag and must be included.

Line 6: This line closes the reference tag and must be included.

To try this code out, login to your Magento Admin, go to your Homepage CMS Page and copy the code into the Layout Update XML field and save the page. Now, if you go to your homepage, you should see your recent posts block.

Filtering the WordPress Post List by a Category ID

Sometimes you may only want to show recent posts from a certain category instead of listing all posts. Using the above the code, we can add 1 extra line to accomplish this.


<reference name="content">
	<block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" as="recent_posts" template="wordpress/sidebar/widget/posts.phtml">
		<action method="setTitle"><title>Latest Posts</title></action>
		<action method="setPostCount"><post_count>5</post_count></action>
		<action method="setCategoryId"><id>1</id></action>
	</block>
</reference>

In the above example, we have added line 5, which simply tells Magento to only display posts from the WordPress category with the ID of 1.

Filtering the WordPress Post List by an Author ID

Another popular filter is the Author ID filter, which as the name suggest, allows you to display posts by a specific author.


<reference name="content">
	<block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" as="recent_posts" template="wordpress/sidebar/widget/posts.phtml">
		<action method="setTitle"><title>Latest Posts</title></action>
		<action method="setPostCount"><post_count>5</post_count></action>
		<action method="setAuthorId"><id>1</id></action>
	</block>
</reference>

In the above example, we have added line 5, which simply tells Magento to only display posts from the WordPress author with the ID of 1.

Filtering by a Category ID and a Author ID

To display posts written by a specific author and published in a specific category, use the following code.


<reference name="content">
	<block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" as="recent_posts" template="wordpress/sidebar/widget/posts.phtml">
		<action method="setTitle"><title>Latest Posts</title></action>
		<action method="setPostCount"><post_count>5</post_count></action>
		<action method="setCategoryId"><id>1</id></action>
		<action method="setAuthorId"><id>1</id></action>
	</block>
</reference>

Filtering by a Custom Post Type

If you're using the Custom Post Types extension, you can filter this block by a specific custom post type.


<reference name="content">
	<block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" as="recent_posts" template="wordpress/sidebar/widget/posts.phtml">
		<action method="setTitle"><title>Latest Posts</title></action>
		<action method="setPostType"><type>article</type></action>
	</block>
</reference>

Display Post Excerpt and Other Post Information

By making some small changes to the XML, you can display more information about each post. The following code illustrates this.


<reference name="content">
	<block type="wordpress/sidebar_widget_posts" name="wordpress.widget.recent_posts" as="recent_posts" template="wordpress/sidebar/widget/categoryposts.phtml">
		<action method="setTitle"><title>Latest Posts</title></action>
		<action method="setPostCount"><post_count>5</post_count></action>
		<action method="setExcerpt"><display>on</display></action>
		<action method="setDate"><date>on</date></action>
		<action method="setCommentNum"><comments>on</comments></action>
	</block>
</reference>

The above code includes the post excerpt, the post date and the comment count for the post! Notice that the template has changed from posts.phtml to categoryposts.phtml. This template is actually used by the Category Posts widget but can be used anywhere on the site using the above XML.

Need More Help?

If you're not a developer, this article might not make much sense to you. If that is the case, we can set up a WordPress recent posts block for you. To purchase this service, click here.

Post your comment

FishPig Ltd