As web developers we like to make use of the best open source platforms available in the development of our brochure and eCommerce websites. We often find that differences in clients needs mean that the solution provided makes use of different platforms such as Magento and WordPress. The following tutorial looks at how products contained within a Magento store can be shared on a WordPress blog.

To pull Magento Products into a WordPress Homepage.

Step 1:


First we will need to create a category in Magento of which we will assign products to (if you are already familiar with creating categories in Magento skip ahead). to create a Category first login to your Magento admin panel and hover over the ‘Catalog’ tab. You will see a sub-navigation item appear of which you will need to select. Click on the ‘Manage Categories’ link.

Step 2:


Once on the manage categories page we will need to create a new category. Click on the ‘Default Category’ option in the left hand sidebar and select ‘Add new sub-category’. This will now load in a new screen where you can configure your category options.  Here you need the following options

Name: (Put whatever you want here we have chosen FeaturedHomepageSidebar)
Is Active: Yes
Url Key: (You can leave this blank)
Thumbnail Image: (You can leave this blank)
Page Title: (You can leave this blank)
Meta Keywords: (You can leave this blank)
Meta Description: (You can leave this blank)
Include in Navigation Menu: No

Note: You may be wondering why we have left a lot of options blank, this is because we will not be using this category as part of our Magento store, it will only ever be called by WordPress.

Finally click on ‘Save Category’ at the top of the screen which will create your new category.

Step 3:


Click on the new category you have just created and note the ID for the new category (I have circled this red for you).

Step 4:


Now that our category is created we need to assign a product into this category, to do this click on the ‘Category Products’ tab and set the dropdown filter to ‘Any’ (circled red) then click search. Your product catalog will then be displayed on screen. To add products into this category select the checkbox that corresponds to the product that you want to add and click on ‘Save Category’.

Step 5:

Now that products have been assigned to our newly created category we can create the php script to pull them out, we will then simply include this file in our wordpress page.  Use the following code below

[pyg language=”php”]

// include the magento core file
require ‘app/Mage.php’;
// create an instance of magento
// replace this with your newly created category id
$category_id = 4;
// load in the category
$_category = Mage::getModel(‘catalog/category’)->load($category_id);
// load in the products that relate to that category
$_products = $_category->getProductCollection();
// create an un-ordered list that loops through the proudcts displaying the product
// image wrapped in an anchor link to the specific product
echo ‘

      foreach($_products as $_product){
      // load the product
      $product = Mage::getModel(‘catalog/product’)

//output the list element, anchor, alt name and image
echo ‘


echo ‘



In summary, the code above created an instance of Magento so that we can access category and product data, we then pass in the category id from the category we created in Step 3 and load in all of the products that are related to that category. Finally we output an un-ordered list of all the products including their images and a link to each specific product.