Magento New Products Block

Magento New Products Block

July 13, 2026 · Illustrated author avatarBy Stefan Bogdanescu
Magento New Products Block

Displaying New Products in Your Magento Store: A Step-by-Step Guide

In Magento, showcasing new products is a crucial aspect of driving customer engagement. If you’re looking to display the latest additions to your store in the right sidebar or dedicated block, I’ll walk you through the process.

Understanding the Layout Structure

Magento’s layout structure is based on XML files that define where blocks are rendered on a page. You can find these files under app/design/frontend/<your_package>/<your_theme>/layout.

For our purpose, we need to modify the catalog_category_view.xml file located in the following path:

app/design/frontend/<your_package>/<your_theme>/layout/catalog.xml

Creating a New Block

The first step is to create a new block that will hold our new products. Open your terminal and navigate to your Magento install directory.

Create a new XML file under app/code/Magento/Widget/etc:

php bin/magento setup:di:compile --clear  # Compile the dependencies

Then, add the following code in the new xml file named new_products.xml:

<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Widget:etc/widget.xsd">
    <widgets>
        <widget id="new_products_widget">
            <label>New Products Widget</label>
            <description type="text">This widget displays the latest products added to the store.</description>
            <default_is_active>true</default_is_active>
            <default_sort_order>10</default_sort_order>
            <settings>
                <sortBy>created_at</sortBy>
                <direction>DESC</direction>
                <limit>6</limit>
            </settings>
        </widget>
    </widgets>
</config>

Configuring the Block

Next, we need to configure the block in our layout file. Open catalog_category_view.xml and add the following code inside the <referenceBlock name="category.products" as="product_listing"> tag:

<block class="Magento\Widget\Block\Widget\AbstractWidget" before="-" template="widget/new_products.phtml">
    <arguments>
        <argument name="widget_id" xsi:type="string">new_products_widget</argument>
    </arguments>
</block>

Creating the Template File

Now, let’s create a new PHTML file for our widget. Navigate to app/design/frontend/<your_package>/<your_theme>/Magento_Widget/templates.

Create a new file named new_products.phtml and add your HTML and PHP code:

<?php $products = $block->getProducts(); ?>
<div class="widget-new-products">
    <h2>New Products</h2>
    <?php foreach ($products as $_product): ?>
        <div class="product-item">
            <h3><?php echo $_product->getName() ?></h3>
            <img src="<?php echo $this->helper('Magento\Catalog\Helper\Image')->init($_product, 'category_page_list')->constrainOnly(TRUE)->keepAspectRatio(TRUE)->keepFrame(FALSE) ?>" />
            <p class="price"><?php echo $_product->getPriceHtml() ?></p>
        </div>
    <?php endforeach; ?>
</div>

Checking the Results

Flush your cache with bin/magento cache:flush and refresh your category page. You should now see a new block displaying the latest products added to your store.

Remember, this is a basic implementation. For a more robust solution, consider using Magento’s Widgets feature or extending the core functionality as described in our official documentation.

Conclusion

Displaying new products in your Magento store can significantly enhance customer interest and drive sales. By following this guide, you’ve learned how to create a custom block, configure it in the layout, and render the necessary template.

Don’t forget that proper caching and performance optimization are crucial for a seamless shopping experience. For more advanced techniques and best practices, I recommend exploring our Magento 2 Development Documentation.

Happy coding!

Catalog Extensions Themes Configuration

Our network