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.
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.
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.
Click on the new category you have just created and note the ID for the new category (I have circled this red for you).
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’.
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
//output the list element, anchor, alt name and image
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.