Show products with specific attribute on cms page

Aurora: 2 weeks ago

I have a question about a specific product collection on a cms page

I have an amount X of products which have an attribute A which is set to true.

Now I want to have a cms page with some content and then have a number of X products on that page where the attribute is true.

I thought of creating a block and then in that block load the collection and then go through that collection until a certain number is reached


Then integrate that block in the cms page

{{block type="custom/list" name="custom_list" template="custom/list.phtml}}

But I want to show X number of products and in 6 columns and wonder how I would achieve this in that way?


Ryleigh: 2 weeks ago

This can be done with a widget. You can set the widget in the admin panel on a CMS block or a CMS page.

Creating a Widget in Magento

We will need the following files:


Define Our Module

<?xml version="1.0"?>

Create a Config File:

<?xml version="1.0"?>

Create a Widget Config

<?xml version="1.0"?>
    <thomas_widget_products type="thomas_widget/widget" translate="name description" module="thomas_widget">
        <name>List of Products</name>
        <description>A List of Products</description>
            <limit translate="label">
                <label>Number of Products</label>

Create a Helper

(For translation)

class Thomas_Widget_Helper_Data 
    extends Mage_Core_Helper_Abstract {


Create a Widget Block Class

class Thomas_Widget_Block_Widget
    extends Mage_Core_Block_Template
    implements Mage_Widget_Block_Interface {

     * Sets the template file
    protected function _construct() {

     * Sets the collection with the "limit" value we pass
    protected function _prepareLayout() {
        /** @var Mage_Catalog_Model_Resource_Product_Collection $collection */
        $collection = Mage::getModel('catalog/product')->getCollection();

        $collection->addFieldToFilter( array(
                array( 'attribute' => 'is_set', 'eq' == 'true' )

        $limit = $this->getLimit(); // limit="5" from widget



Create Template File

/** @var Thomas_Widget_Block_Widget $block */
$block = $this;

$collection = $block->getCollection();

if($collection->getSize() > 0) {
    foreach($collection as $product) {
        // Do something with $product object here

Using The Widget

Now, you can go to your admin panel and set the widget directly:

Widget Menu

You can also set the widget directly with this:

{{widget type="thomas_widget/widget" limit="5"}}


This is a basic example. You can go crazy with widgets. You can even define the attribute to filter with!

I hope this helps. Good luck with your widget making!