Advertisement
  1. Web Design
  2. HTML/CSS
  3. HTML

Magento Theme Development: Home Page, Part 3

Scroll to top
Read Time: 10 min
This post is part of a series called Magento Theme Development.
Magento Theme Development: Home Page, Part 2
Magento Theme Development: Home Page Styling

Now that we have completely customized the first half of the home page, we need to modify the content of the home page next. If we look at our HTML design, the home-page content section has just one heading and a carousel for the latest products. There is a Magento widget we can use to show the latest products on the home page. Actually, if we look at our current home-page section, it already has the latest products widget enabled on it, but we need to modify it to match our design requirements.

If we look at the content of our home page by going to the Admin Panel > CMS > Pages > Madison Island > Content, we’ll see that there is only one line of PHP code (other than some style tags), i.e.:

1
{{widget type="catalog/product_widget_new" display_type="new_products" products_count="5" template="catalog/product/widget/new/content/new_grid.phtml"}}

So, basically all the home-page content is coming from this template (which is just a template for showing new products). We’ll copy this file from the RWD theme to our new theme, in catalog/product/widget/new/content/new_grid.phtml, and start editing it to make it look like our HTML design. If we look at the current code of this file, it is:

1
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
2
<div class="widget widget-new-products">
3
    <div class="widget-title">
4
        <h2><?php echo $this->__('New Products') ?></h2>
5
    </div>
6
    <div class="widget-products">
7
        <?php echo $this->getPagerHtml() ?>
8
        <?php $_columnCount = $this->getColumnCount(); ?>
9
        <?php $i=0; ?>
10
        <ul class="products-grid products-grid--max-<?php echo $_columnCount; ?>-col">
11
            <?php foreach ($_products->getItems() as $_product): ?>
12
                <li class="item<?php if(($i-1)%$_columnCount==0): ?> first<?php elseif($i%$_columnCount==0): ?> last<?php endif; ?>">
13
                    <?php $_imgSize = 210; ?>
14
                    <a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>" class="product-image">
15
                        <img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(85) ?>" alt="<?php echo $this->stripTags($_product->getName(), null, true) ?>" />
16
                    </a>
17
                    <div class="product-info">
18
                        <h3 class="product-name"><a href="<?php echo $_product->getProductUrl() ?>" title="<?php echo $this->stripTags($_product->getName(), null, true) ?>)"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></a></h3>
19
                        <?php echo $this->getPriceHtml($_product, true, '-widget-new-grid') ?>
20
                        <?php echo $this->getReviewsSummaryHtml($_product, 'short') ?>
21
                        <div class="actions">
22
                            <?php if ($_product->isSaleable()): ?>
23
                                <button type="button" title="<?php echo $this->__('Add to Cart') ?>" class="button btn-cart" onclick="setLocation('<?php echo $this->getAddToCartUrl($_product) ?>')"><span><span><?php echo $this->__('Add to Cart') ?></span></span></button>
24
                            <?php else: ?>
25
                                <p class="availability out-of-stock"><span><?php echo $this->__('Out of stock') ?></span></p>
26
                            <?php endif; ?>
27
                            <ul class="add-to-links">
28
                                <?php if ($this->helper('wishlist')->isAllow()) : ?>
29
                                    <li><a href="<?php echo $this->getAddToWishlistUrl($_product) ?>" class="link-wishlist"><?php echo $this->__('Add to Wishlist') ?></a></li>
30
                                <?php endif; ?>
31
                                <?php if($_compareUrl=$this->getAddToCompareUrl($_product)): ?>
32
                                    <li><span class="separator">|</span> <a href="<?php echo $_compareUrl ?>" class="link-compare"><?php echo $this->__('Add to Compare') ?></a></li>
33
                                <?php endif; ?>
34
                            </ul>
35
                        </div>
36
                    </div>
37
                </li>
38
            <?php endforeach; ?>
39
        </ul>
40
    </div>
41
</div>
42
<?php endif; ?>

When we look at our HTML code for this section, it looks like this:

1
<div class="container_fullwidth">
2
    <div class="container">
3
        <h3 class="title"><strong>Hot</strong> Products</h3>
4
        <div class="clearfix"></div>
5
    	<div id="owl-demo" class="owl-carousel">
6
            <div class="item">
7
                <div class="products">
8
                    <div class="main">
9
                        <div class="view view-eighth">
10
                            <img src="images/products/small/products-02.jpg" />
11
                            <div class="mask">
12
                                <a href="#" class="info">Add to Cart</a>
13
                            </div>
14
                            <div class="productname">Iphone 5s Gold 32 Gb 2013</div>
15
                            <h4 class="price">$451.00</h4>
16
                        </div>
17
                    </div>
18
                </div>
19
            </div>
20
</div>

So, we’ll start by plugging in the dynamic tags in this HTML. The reason I’ve shown you the current code of this file is so that you can find the required dynamic tags from that code, and put them in the HTML.

We don’t have to make any changes to the div structure, so the first line which needs to change is the h3 tag:

1
<h3 class="title"><strong>Hot</strong> Products</h3>

We need to replace the static text of Hot and Products with Magento $this tags, so that Magento can later translate these according to user preferences. So, this line will become something like this: 

1
<h3 class="title"><strong><?php echo $this->__('New') ?></strong><?php echo $this->__(' Products') ?></h3>

The next line which needs to change is the image tag, where we need to change the relevant path of the image source. Currently it looks like this:

1
<img src="images/products/small/products-02.jpg" />

We’ll change it to this:

1
<img src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(236, 357) ?>"/>

Here this dynamic tag will get the actual small image of the product of 236 x 357 px size. Next, we need to change this Add to Cart link:

1
<a href="#" class="info">Add to Cart</a>

We’ll change it to this:

1
<a href="<?php echo $_product->getProductUrl() ?>" class="info">
2
    <?php if ($_product->isSaleable()): ?>
3
        <?php echo $this->__('Add to Cart') ?>
4
    <?php else: ?>
5
        <?php echo $this->__('Out of stock') ?>
6
    <?php endif; ?>
7
</a>

It has a dynamic URL for the product details page, and only shows ‘Add to Cart’ if the product is available. Otherwise it’ll show ‘Out of Stock’. Lastly, we’ll update the product price and name, by replacing this line:

1
<div class="productname">Iphone 5s Gold 32 Gb 2013</div>
2
<h4 class="price">$451.00</h4>

With this one: 

1
<div class="productname"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></div>
2
<h4 class="price"><?php echo $this->getPriceHtml($_product, true, '-widget-new-grid') ?></h4>

This will have our single product view ready, but to iterate it over all new products, we have to enclose our item div in a loop, so we’ll add this line at the top of it:

1
<?php foreach ($_products->getItems() as $_product): ?>

And this line at the end of it to terminate the loop:

1
<?php endforeach; ?>

So the full code for that file will become like this:

1
<?php if (($_products = $this->getProductCollection()) && $_products->getSize()): ?>
2
    <div class="container_fullwidth">
3
        <div class="container">
4
            <h3 class="title"><strong><?php echo $this->__('New') ?></strong><?php echo $this->__(' Products') ?></h3>
5
            <div class="clearfix"></div>
6
            <div id="owl-demo" class="owl-carousel">
7
                <?php foreach ($_products->getItems() as $_product): ?>
8
                    <div class="item">
9
                        <div class="products">
10
                            <div class="main">
11
                                <div class="view view-eighth">
12
                                        <img
13
                                            src="<?php echo $this->helper('catalog/image')->init($_product, 'small_image')->resize(236, 357) ?>"/>
14
15
                                    <div class="mask">
16
                                        <a href="<?php echo $_product->getProductUrl() ?>" class="info">
17
                                            <?php if ($_product->isSaleable()): ?>
18
                                                <?php echo $this->__('Add to Cart') ?>
19
                                            <?php else: ?>
20
                                                <?php echo $this->__('Out of stock') ?>
21
                                            <?php endif; ?>
22
                                        </a>
23
                                    </div>
24
                                        <div class="productname"><?php echo $this->helper('catalog/output')->productAttribute($_product, $_product->getName() , 'name') ?></div>
25
                                        <h4 class="price"><?php echo $this->getPriceHtml($_product, true, '-widget-new-grid') ?></h4>
26
                                </div>
27
                            </div>
28
                        </div>
29
                    </div>
30
                <?php endforeach; ?>
31
            </div>
32
        </div>
33
    </div>
34
<?php endif; ?>

Refresh your home page now. It should have a perfectly working and styled new products section, which would look like this:

Latest Product CarousalLatest Product CarousalLatest Product Carousal

Now we need to modify the footer before we are done with the home page. If we look at our HTML design, the footer has four sections. The first one shows ‘Our Brands’, the second one shows a subscribe box and social media links, the third one shows some URLs, and the fourth one just the copyright notice.

Footer SectionsFooter SectionsFooter Sections

The fourth section is already present in our theme, so we just have to modify the content and styles, but the other three components we have to add in our theme. 

To add a component, we’ll create a new Static Block from the admin panel and put our content in there. So, we’ll go to Admin Panel > Static Blocks > Add New Block, and add a new block for the Our Brands section. We’ll change the Block title to ‘Our Brands’, set the identifier to ‘our_brands’, select the store view of ‘All Store Views’, and put this in the content section:

1
<h3 class="title"><strong>Our </strong> Brands</h3>
2
    <div class="control"><a id="prev_brand" class="prev" href="#">&lt;</a><a id="next_brand" class="next" href="#">&gt;</a></div>
3
    <ul id="braldLogo">
4
        <li>
5
            <ul class="brand_item">
6
                <li><a href="#">
7
                        <div class="brand-logo"><img src="{{media url="wysiwyg/myuploads/envato.png"}}" alt="" /></div>
8
                    </a></li>
9
                <li><a href="#">
10
                        <div class="brand-logo"><img src="{{media url="wysiwyg/myuploads/themeforest.png"}}" alt="" /></div>
11
                    </a></li>
12
                <li><a href="#">
13
                        <div class="brand-logo"><img src="{{media url="wysiwyg/myuploads/photodune.png"}}" alt="" /></div>
14
                    </a></li>
15
                <li><a href="#">
16
                        <div class="brand-logo"><img src="{{media url="wysiwyg/myuploads/activeden.png"}}" alt="" /></div>
17
                    </a></li>
18
                <li><a href="#">
19
                        <div class="brand-logo"><img src="{{media url="wysiwyg/myuploads/envato.png"}}" alt="" /></div>
20
                    </a></li>
21
            </ul>
22
        </li>
23
        <li>
24
            <ul class="brand_item">
25
                <li><a href="#">
26
                        <div class="brand-logo"><img src="{{media url="wysiwyg/myuploads/envato.png"}}" alt="" /></div>
27
                    </a></li>
28
                <li><a href="#">
29
                        <div class="brand-logo"><img src="{{media url="wysiwyg/myuploads/themeforest.png"}}" alt="" /></div>
30
                    </a></li>
31
                <li><a href="#">
32
                        <div class="brand-logo"><img src="{{media url="wysiwyg/myuploads/photodune.png"}}" alt="" /></div>
33
                    </a></li>
34
                <li><a href="#">
35
                        <div class="brand-logo"><img src="{{media url="wysiwyg/myuploads/activeden.png"}}" alt="" /></div>
36
                    </a></li>
37
                <li><a href="#">
38
                        <div class="brand-logo"><img src="{{media url="wysiwyg/myuploads/envato.png"}}" alt="" /></div>
39
                    </a></li>
40
            </ul>
41
        </li>
42
    </ul>

If you look closely, it is the same code as we have in our HTML for this section—we have just changed the relative paths of the images, while manually uploading the new images from within the WYSIWYG editor. Save the block, and start creating another block for the signup section.

For this second block, we’ll use the block title of ‘Above Footer’. For the identifier we’ll use ‘above_footer’, and for the content we’ll enter this code:

1
<div class="col-md-5">
2
    <form class="newsletter">
3
        <input type="text" name="" placeholder="Type your email....">
4
        <input type="submit" value="SignUp" class="button">
5
    </form>
6
</div>
7
<div class="col-md-6">
8
    <ul class="social-icon">
9
        <li><a href="#" class="linkedin"></a></li>
10
        <li><a href="#" class="google-plus"></a></li>
11
        <li><a href="#" class="twitter"></a></li>
12
        <li><a href="#" class="facebook"></a></li>
13
    </ul>
14
</div>

Now we have to create the links block in a similar way. We’ll create a new block with the Block title of ‘Footer Links’, with the identifier as ‘footer_links’, and put this code in there:

1
<div class="col-md-3 col-sm-6">
2
    <h4 class="title">Customer<strong> Support</strong></h4>
3
    <ul class="support">
4
        <li><a href="#">FAQ</a></li>
5
        <li><a href="#">Payment Option</a></li>
6
        <li><a href="#">Booking Tips</a></li>
7
        <li><a href="#">Infomation</a></li>
8
    </ul>
9
</div>
10
<div class="col-md-3 col-sm-6">
11
    <h4 class="title">Customer<strong> Support</strong></h4>
12
    <ul class="support">
13
        <li><a href="#">FAQ</a></li>
14
        <li><a href="#">Payment Option</a></li>
15
        <li><a href="#">Booking Tips</a></li>
16
        <li><a href="#">Infomation</a></li>
17
    </ul>
18
</div>
19
<div class="col-md-3 col-sm-6">
20
    <h4 class="title">Customer<strong> Support</strong></h4>
21
    <ul class="support">
22
        <li><a href="#">FAQ</a></li>
23
        <li><a href="#">Payment Option</a></li>
24
        <li><a href="#">Booking Tips</a></li>
25
        <li><a href="#">Infomation</a></li>
26
    </ul>
27
</div>
28
<div class="col-md-3 col-sm-6">
29
    <h4 class="title">Contact <strong>Info</strong></h4>
30
    <p><span><img src="{{media url="wysiwyg/myuploads/placeIcon.jpg"}}" alt="" /></span>Anwar ul Haq , California</p>
31
    <p><span><img src="{{media url="wysiwyg/myuploads/phoneIcon.jpg"}}" alt="" /></span>Call Us : (123) 398 5063</p>
32
    <p><span><img src="{{media url="wysiwyg/myuploads/mobileIcon.jpg"}}" alt="" /></span>Call Us : (123) 398 5063</p>
33
    <p><span><img src="{{media url="wysiwyg/myuploads/mailIcon.jpg"}}" alt="" /></span>Email : abs@tutsplus</p>
34
</div>

All these links are linking nowhere now, but you can later modify them. The image links are again dynamically generated using the upload feature of the WYSIWYG editor. All the rest of the code is just copied and pasted from the HTML.

Save this block too, and check the home page, but still you won’t see these three blocks showing up. This is because you have to tell Magento explicitly where to show these new blocks, and that we can do from the layout section. For this, go to the layout/local.xml file, and add these lines, just before the closing of the default tag.

1
<reference name="footer">
2
    <block type="cms/block" name="footer_links ">
3
        <action method="setBlockId"><block_id>footer_links</block_id></action>
4
    </block>    
5
    <block type="cms/block" name="above_footer">
6
        <action method="setBlockId"><block_id>above_footer</block_id></action>
7
    </block>
8
    <block type="cms/block" name="our_brands">
9
        <action method="setBlockId"><block_id>our_brands</block_id></action>
10
    </block>
11
</reference>

This XML code is basically telling Magento to add these two new blocks into the Magento footer section. Lastly, we need to call these blocks from the footer phtml file. For that we’ll create a new footer.phtml file at this location: template/page/html/footer.phtml.

Add this code in this footer.phtml file: 

1
<div class="container_fullwidth">
2
    <div class="container">
3
        <div class="our-brand">
4
            <?php echo $this->getChildHtml("our_brands") ?>
5
        </div>
6
    </div>
7
    <div class="clearfix"></div>
8
    <div class="footer">
9
        <div class="copyright-info">
10
            <div class="container">
11
                <div class="row">
12
                    <?php echo $this->getChildHtml("above_footer") ?>
13
                </div>
14
            </div>
15
        </div>
16
        <div class="footer-info">
17
            <div class="container">
18
                <div class="row">
19
                    <?php echo $this->getChildHtml("footer_links_sm") ?>
20
                    <?php // echo $this->getChildHtml() ?>

21
                </div>
22
            </div>
23
        </div>
24
        <div class="copyright-info">
25
            <div class="container">
26
                <div class="row">
27
                    <div class="col-md-12">
28
                        <p><?php echo $this->getCopyright() ?></p>
29
                    </div>
30
                </div>
31
            </div>
32
        </div>
33
    </div>
34
    </div>

This is again just HTML code taken, where all the section codes are replaced with relevant links to Static Blocks. And the copyright section is replaced with a copyright dynamic tag.

Check the home page now, and it should now show these newly created Static Blocks, and should look like this:

Complete HomepageComplete HomepageComplete Homepage

Our home page is now complete. The only thing left is some style fixing, and we’ll do that in the next article.

Advertisement
Did you find this post useful?
Want a weekly email summary?
Subscribe below and we’ll send you a weekly email summary of all new Web Design tutorials. Never miss out on learning about the next big thing.
Advertisement
Looking for something to help kick start your next project?
Envato Market has a range of items for sale to help get you started.