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

Magento Theme Development: Home Page, Part 1

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

As we set the stage in the previous bootstrapping article, now is the time to actually dive deep into the code, and start making changes. As an obvious choice, we'll start the editing process from the home page. 

In this first article we'll be partially editing the header section. We'll edit the default wrapper files and the header.phtml file, and then we'll start editing the different components of header like currency, language selector, etc. So, without further ado, we'll start the editing process. 

First of all, we’ll enable the Template hints from the admin panel, by going to System > Developer > Debug, and while doing so we'll make sure that Current Configuration Scope is set to Main Website. By enabling template hints, we’ll know which template is responsible for the header styles. This is how the home page will look when the template hints are on.

Homepage with template hintsHomepage with template hintsHomepage with template hints

Here, as you can see, the outermost wrapper in which all other files are included is coming from frontend/rwd/default/template/page/1column.phtml, which is from the RWD theme, as we have inherited our theme from this default theme. Instead of editing this file directly in the RWD theme, we’ll create a similar folder in our vstyle theme at this location: frontend/tutsplus/vstyle/template/page. Then we'll copy these files into this folder, and edit them there. So, we’ll go to the frontend/rwd/default/template/page directory and copy 1column.phtml, 2column-left.phtml, 2column-right.phtml, and 3column.phtml into this newly created folder.

If we look at the code of 1-column.phtml, it is like this:

1
<!DOCTYPE html>
2
3
<!--[if lt IE 7 ]> <html lang="<?php echo $this->getLang(); ?>" id="top" class="no-js ie6"> <![endif]-->
4
<!--[if IE 7 ]>    <html lang="<?php echo $this->getLang(); ?>" id="top" class="no-js ie7"> <![endif]-->
5
<!--[if IE 8 ]>    <html lang="<?php echo $this->getLang(); ?>" id="top" class="no-js ie8"> <![endif]-->
6
<!--[if IE 9 ]>    <html lang="<?php echo $this->getLang(); ?>" id="top" class="no-js ie9"> <![endif]-->
7
<!--[if (gt IE 9)|!(IE)]><!--> <html lang="<?php echo $this->getLang(); ?>" id="top" class="no-js"> <!--<![endif]-->
8
9
<head>
10
<?php echo $this->getChildHtml('head') ?>
11
</head>
12
<body<?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
13
<?php echo $this->getChildHtml('after_body_start') ?>
14
<div class="wrapper">
15
    <?php echo $this->getChildHtml('global_notices') ?>
16
    <div class="page">
17
        <?php echo $this->getChildHtml('header') ?>
18
        <div class="main-container col1-layout">
19
            <div class="main">
20
                <?php echo $this->getChildHtml('breadcrumbs') ?>
21
                <div class="col-main">
22
                    <?php echo $this->getChildHtml('global_messages') ?>
23
                    <?php echo $this->getChildHtml('content') ?>
24
                </div>
25
            </div>
26
        </div>
27
        <?php echo $this->getChildHtml('footer_before') ?>
28
        <?php echo $this->getChildHtml('footer') ?>
29
        <?php echo $this->getChildHtml('global_cookie_notice') ?>
30
        <?php echo $this->getChildHtml('before_body_end') ?>
31
    </div>
32
</div>
33
<?php echo $this->getAbsoluteFooter() ?>
34
</body>
35
</html>

Now we have to modify it to match our index.html file, so we’ll use our body and container classes, and add some extra divs, and the edited code will look like this:

1
<!DOCTYPE html>
2
<html>
3
4
<head>
5
    <?php echo $this->getChildHtml('head') ?>
6
</head>
7
<body id="home" <?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
8
<?php echo $this->getChildHtml('after_body_start') ?>
9
10
<div class="wrapper">
11
    <?php echo $this->getChildHtml('global_notices') ?>
12
13
    <?php echo $this->getChildHtml('header') ?>
14
15
    <div class="container_fullwidth">
16
        <div class="container">
17
            <?php echo $this->getChildHtml('global_messages') ?>
18
            <?php echo $this->getChildHtml('content') ?>
19
        </div>
20
    </div>
21
    <div class="clearfix"></div>
22
    <div class="footer">
23
        <?php echo $this->getChildHtml('footer_before') ?>
24
        <?php echo $this->getChildHtml('footer') ?>
25
        <?php echo $this->getChildHtml('global_cookie_notice') ?>
26
        <?php echo $this->getChildHtml('before_body_end') ?>
27
    </div>
28
</div>
29
30
<?php echo $this->getAbsoluteFooter() ?>
31
</body>
32
</html>

Similarly we are also going to edit the 2column-left.phtml, 2column-right.phtml, and 3column.phtml files. This is how the modified code will look for 2-column-left.phtml:

1
<!DOCTYPE html>
2
<html>
3
4
<head>
5
    <?php echo $this->getChildHtml('head') ?>
6
</head>
7
<body id="home" <?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
8
<?php echo $this->getChildHtml('after_body_start') ?>
9
10
<div class="wrapper">
11
    <?php echo $this->getChildHtml('global_notices') ?>
12
13
    <?php echo $this->getChildHtml('header') ?>
14
15
    <div class="container_fullwidth">
16
        <div class="container">
17
            <div class="row">
18
                <div class="col-md-3">
19
                    <?php echo $this->getChildHtml('left') ?>
20
                </div>
21
                <div class="col-md-9">
22
                    <?php echo $this->getChildHtml('global_messages') ?>
23
                    <?php echo $this->getChildHtml('content') ?>
24
                </div>
25
            </div>
26
        </div>
27
    </div>
28
    <div class="clearfix"></div>
29
    <div class="footer">
30
        <?php echo $this->getChildHtml('footer_before') ?>
31
        <?php echo $this->getChildHtml('footer') ?>
32
        <?php echo $this->getChildHtml('global_cookie_notice') ?>
33
        <?php echo $this->getChildHtml('before_body_end') ?>
34
    </div>
35
</div>
36
37
<?php echo $this->getAbsoluteFooter() ?>
38
</body>
39
</html>

Next, 2columns-right.phtml will look like this after the editing: 

1
<!DOCTYPE html>
2
<html>
3
4
<head>
5
    <?php echo $this->getChildHtml('head') ?>
6
</head>
7
<body id="home" <?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
8
<?php echo $this->getChildHtml('after_body_start') ?>
9
10
<div class="wrapper">
11
    <?php echo $this->getChildHtml('global_notices') ?>
12
13
    <?php echo $this->getChildHtml('header') ?>
14
15
    <div class="container_fullwidth">
16
        <div class="container">
17
            <div class="row">
18
                <div class="col-md-9">
19
                    <?php echo $this->getChildHtml('global_messages') ?>
20
                    <?php echo $this->getChildHtml('content') ?>
21
                </div>
22
                <div class="col-md-3">
23
                    <?php echo $this->getChildHtml('right') ?>
24
                </div>
25
            </div>
26
        </div>
27
    </div>
28
    <div class="clearfix"></div>
29
    <div class="footer">
30
        <?php echo $this->getChildHtml('footer_before') ?>
31
        <?php echo $this->getChildHtml('footer') ?>
32
        <?php echo $this->getChildHtml('global_cookie_notice') ?>
33
        <?php echo $this->getChildHtml('before_body_end') ?>
34
    </div>
35
</div>
36
37
<?php echo $this->getAbsoluteFooter() ?>
38
</body>
39
</html>

Lastly, we are going to edit 3columns.phtml like this:

1
<!DOCTYPE html>
2
<html>
3
4
<head>
5
    <?php echo $this->getChildHtml('head') ?>
6
</head>
7
<body id="home" <?php echo $this->getBodyClass()?' class="'.$this->getBodyClass().'"':'' ?>>
8
<?php echo $this->getChildHtml('after_body_start') ?>
9
10
<div class="wrapper">
11
    <?php echo $this->getChildHtml('global_notices') ?>
12
13
    <?php echo $this->getChildHtml('header') ?>
14
15
    <div class="container_fullwidth">
16
        <div class="container">
17
            <div class="row">
18
                <div class="col-md-3">
19
                    <?php echo $this->getChildHtml('left') ?>
20
                </div>
21
                <div class="col-md-6">
22
                    <?php echo $this->getChildHtml('global_messages') ?>
23
                    <?php echo $this->getChildHtml('content') ?>
24
                </div>
25
                <div class="col-md-3">
26
                    <?php echo $this->getChildHtml('right') ?>
27
                </div>
28
            </div>
29
        </div>
30
    </div>
31
    <div class="clearfix"></div>
32
    <div class="footer">
33
        <?php echo $this->getChildHtml('footer_before') ?>
34
        <?php echo $this->getChildHtml('footer') ?>
35
        <?php echo $this->getChildHtml('global_cookie_notice') ?>
36
        <?php echo $this->getChildHtml('before_body_end') ?>
37
    </div>
38
</div>
39
40
<?php echo $this->getAbsoluteFooter() ?>
41
</body>
42
</html>

Look carefully at the changes we have made in these template files. When you compare it to the index.html file of our HTML website, it’ll make sense to you.

This is how the website should look after editing these files. You won’t see much difference, but we are heading in the right direction.

Homepage with wrapper files modifiedHomepage with wrapper files modifiedHomepage with wrapper files modified

Next we are going to edit the header.phtml file, as we can see that this is the file which has the wrapper content of the header section. So, we’ll copy the frontend/rwd/default/template/page/html/header.phtml file, move it to the frontend/tutsplus/vstyle/template/page/html folder, and start editing it. Currently its code will look like this:

1
<div class="header-language-background">
2
    <div class="header-language-container">
3
        <div class="store-language-container">
4
            <?php echo $this->getChildHtml('store_language') ?>
5
        </div>
6
7
        <?php echo $this->getChildHtml('currency_switcher') ?>
8
9
        <p class="welcome-msg"><?php echo $this->getChildHtml('welcome') ?> <?php echo $this->getAdditionalHtml() ?></p>
10
    </div>
11
</div>
12
13
<header id="header" class="page-header">
14
    <div class="page-header-container">
15
        <a class="logo" href="<?php echo $this->getUrl('') ?>">
16
            <img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" class="large" />
17
            <img src="<?php echo $this->getLogoSrcSmall() ?>" alt="<?php echo $this->getLogoAlt() ?>" class="small" />
18
        </a>
19
20
        <?php // In order for the language switcher to display next to logo on smaller viewports, it will be moved here.

21
              // See app.js for details ?>

22
        <div class="store-language-container"></div>
23
24
        <!-- Skip Links -->
25
26
        <div class="skip-links">
27
            <a href="#header-nav" class="skip-link skip-nav">
28
                <span class="icon"></span>
29
                <span class="label"><?php echo $this->__('Menu'); ?></span>
30
            </a>
31
32
            <a href="#header-search" class="skip-link skip-search">
33
                <span class="icon"></span>
34
                <span class="label"><?php echo $this->__('Search'); ?></span>
35
            </a>
36
37
            <div class="account-cart-wrapper">
38
                <a href="<?php echo $this->helper('customer')->getAccountUrl(); ?>" data-target-element="#header-account" class="skip-link skip-account">
39
                    <span class="icon"></span>
40
                    <span class="label"><?php echo $this->__('Account'); ?></span>
41
                </a>
42
43
                <!-- Cart -->
44
45
                <div class="header-minicart">
46
                    <?php echo $this->getChildHtml('minicart_head'); ?>
47
                </div>
48
            </div>
49
50
51
        </div>
52
53
        <!-- Navigation -->
54
55
        <div id="header-nav" class="skip-content">
56
            <?php echo $this->getChildHtml('topMenu') ?>
57
        </div>
58
59
        <!-- Search -->
60
61
        <div id="header-search" class="skip-content">
62
            <?php echo $this->getChildHtml('topSearch') ?>
63
        </div>
64
65
        <!-- Account -->
66
67
        <div id="header-account" class="skip-content">
68
            <?php echo $this->getChildHtml('topLinks') ?>
69
        </div>
70
    </div>
71
</header>
72
73
74
<?php echo $this->getChildHtml('topContainer'); ?>

We’ll compare it to the header section of our HTML, and start making these changes in it:

1
<div class="header">
2
    <div class="container">
3
      <div class="row">
4
          <div class="col-md-12 col-sm-10">
5
          <div class="phoneNum pull-left">
6
          	<p>Call us now! 0800-123-456-78</p>
7
          </div>    
8
          <div class="header_top">
9
            <div class="row">
10
              <ul class="option_nav">
11
                  <li class="dropdown"><a href="checkout.html" class="log"><img src="images/language.jpg" alt=""></a>
12
                    <ul class="subnav">
13
                      <li><a href="#">Eng</a></li>
14
                      <li><a href="#">Vns</a></li>
15
                      <li><a href="#">Fer</a></li>
16
                      <li><a href="#">Gem</a></li>
17
                    </ul>
18
                  </li>
19
                  <li class="dropdown"><a href="checkout.html" class="log"><img src="images/doller.jpg" alt=""></a>
20
                    <ul class="subnav">
21
                      <li><a href="#">USD</a></li>
22
                      <li><a href="#">UKD</a></li>
23
                      <li><a href="#">FER</a></li>
24
                    </ul>
25
                  </li>
26
                </ul>
27
              <ul class="usermenu">
28
                  <li><a href="checkout.html" class="log"><img src="images/user.jpg" alt=""></a></li>
29
              </ul>
30
              <ul class="option">
31
                  <li class="option-cart"><a href="#" class="cart-icon">cart <!--<span class="cart_no">02</span>--></a>
32
                <ul class="option-cart-item">
33
                  <li>
34
                    <div class="cart-item">
35
                      <div class="image"><img src="images/products/thum/products-01.png" alt=""></div>
36
                      <div class="item-description">
37
                        <p class="name">Lincoln chair</p>
38
                        <p>Size: <span class="light-red">One size</span><br>
39
                          Quantity: <span class="light-red">01</span></p>
40
                      </div>
41
                      <div class="right">
42
                        <p class="price">$30.00</p>
43
                        <a href="#" class="remove"><img src="images/remove.png" alt="remove"></a></div>
44
                    </div>
45
                  </li>
46
                  <li>
47
                    <div class="cart-item">
48
                      <div class="image"><img src="images/products/thum/products-02.png" alt=""></div>
49
                      <div class="item-description">
50
                        <p class="name">Lincoln chair</p>
51
                        <p>Size: <span class="light-red">One size</span><br>
52
                          Quantity: <span class="light-red">01</span></p>
53
                      </div>
54
                      <div class="right">
55
                        <p class="price">$30.00</p>
56
                        <a href="#" class="remove"><img src="images/remove.png" alt="remove"></a></div>
57
                    </div>
58
                  </li>
59
                  <li><span class="total">Total <strong>$60.00</strong></span>
60
                    <button class="checkout" onClick="location.href='checkout.html'">CheckOut</button>
61
                  </li>
62
                </ul>
63
              </li>
64
            </ul>
65
            </div>
66
          </div>
67
68
        </div>
69
      </div>
70
    </div>
71
  </div>

We’ll insert this HTML into the header.phtml file, and replace difference sections with the relevant dynamic template tags like currency switcher, store language, logo, menu, search bar, etc. This is how the code will look after these edits:

1
<div class="header">
2
    <div class="container">
3
        <div class="row">
4
            <div class="col-md-12 col-sm-10">
5
                <div class="phoneNum pull-left">
6
                    <p><?php echo $this->getChildHtml('welcome') ?> <?php echo $this->getAdditionalHtml() ?></p>
7
                </div>
8
                <div class="header_top">
9
                    <div class="row">
10
                        <ul class="option_nav">
11
                                <?php echo $this->getChildHtml('currency_switcher') ?>
12
                                <?php echo $this->getChildHtml('store_language') ?>
13
                        </ul>
14
                        <ul class="usermenu">
15
                            <li><a href="<?php echo Mage::getUrl('customer/account'); ?>" class="log"><img src="<?php echo $this->getSkinUrl('images/user.jpg'); ?>" alt=""></a></li>
16
                        </ul>
17
                        <ul class="option">
18
                            <li class="option-cart">
19
                                <?php echo $this->getChildHtml('minicart_head'); ?>
20
                            </li>
21
                        </ul>
22
                    </div>
23
                </div>
24
25
            </div>
26
        </div>
27
    </div>
28
</div>
29
30
<div class="logoContainer">
31
    <div class="container">
32
        <div class="row">
33
            <div class="col-md-12 col-sm-2">
34
                <div class="logoBox">
35
                    <a class="logo" href="<?php echo $this->getUrl('') ?>">
36
                        <img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" class="large" />
37
                        <img src="<?php echo $this->getLogoSrcSmall() ?>" alt="<?php echo $this->getLogoAlt() ?>" class="small" />
38
                    </a>
39
                </div>
40
            </div>
41
        </div>
42
    </div>
43
</div>
44
45
<div class="menu">
46
    <div class="container">
47
        <div class="row">
48
            <div class="col-md-9 col-sm-10">
49
                <div id="header-nav" class="skip-content">
50
                    <?php echo $this->getChildHtml('topMenu') ?>
51
                </div>
52
            </div>
53
            <div class="col-md-3 col-sm-2">
54
                <div class="search">
55
                    <div id="header-search" class="skip-content">
56
                        <?php echo $this->getChildHtml('topSearch') ?>
57
                    </div>
58
                </div>
59
            </div>
60
        </div>
61
    </div>
62
</div>
63
64
<?php echo $this->getChildHtml('topContainer'); ?>

This is how the header section will look after editing the header.phtml file:

Afer editing headerphtml fileAfer editing headerphtml fileAfer editing headerphtml file

Now as you can see, we need to modify the code of different sections we are using, like language and currency selector, slider, menu, search bar, etc. To start with, we’ll edit the currency and language selectors. If we again enable the template hints, we can see that language selector section is coming from base/default/template/page/switch/languages.phtml, so we’ll copy this file into our theme at the same location, and start editing it to match our HTML code. The original languages.phtml file looks like this:

1
<?php if(count($this->getStores())>1): ?>
2
<div class="form-language">
3
    <label for="select-language"><?php echo $this->__('Your Language:') ?></label>
4
    <select id="select-language" title="<?php echo $this->__('Your Language') ?>" onchange="window.location.href=this.value">
5
    <?php foreach ($this->getStores() as $_lang): ?>
6
        <?php $_selected = ($_lang->getId() == $this->getCurrentStoreId()) ? ' selected="selected"' : '' ?>
7
        <option value="<?php echo $_lang->getCurrentUrl() ?>"<?php echo $_selected ?>><?php echo $this->escapeHtml($_lang->getName()) ?></option>
8
    <?php endforeach; ?>
9
    </select>
10
</div>
11
<?php endif; ?>

The original HTML code for language and currency selector looks like this:

1
<ul class="option_nav">
2
                  <li class="dropdown"><a href="checkout.html" class="log"><img src="images/language.jpg" alt=""></a>
3
                    <ul class="subnav">
4
                      <li><a href="#">Eng</a></li>
5
                      <li><a href="#">Vns</a></li>
6
                      <li><a href="#">Fer</a></li>
7
                      <li><a href="#">Gem</a></li>
8
                    </ul>
9
                  </li>
10
                  <li class="dropdown"><a href="checkout.html" class="log"><img src="images/doller.jpg" alt=""></a>
11
                    <ul class="subnav">
12
                      <li><a href="#">USD</a></li>
13
                      <li><a href="#">UKD</a></li>
14
                      <li><a href="#">FER</a></li>
15
                    </ul>
16
                  </li>
17
                </ul>

After we modify languages.phtml to match the HTML, it’ll look like this:

1
<?php if(count($this->getStores())>1): ?>
2
<li class="dropdown">
3
    <a href="#" class="log"><img src="<?php echo $this->getSkinUrl('images/doller.jpg'); ?>" alt=""></a>
4
    <ul class="subnav">
5
        <?php foreach ($this->getStores() as $_lang): ?>
6
            <li>
7
                <a href="<?php echo $_lang->getCurrentUrl() ?>">
8
                    <?php
9
                        $langName = $this->escapeHtml($_lang->getName());
10
                        $langName = substr("$langName", 0, 3);
11
                        $langName = strtoupper($langName);
12
                        echo $langName;
13
                    ?>
14
                </a>
15
            </li>
16
        <?php endforeach; ?>
17
    </ul>
18
</li>
19
<?php endif; ?>

As you can see, the currency selector is not showing up on our website for now. We have to enable the currency selector from the admin panel first. From System > Configuration > General > Currency Setup, you have to first enable some languages, and then from System > Manage Currency > Rates set currency rates. Then you’ll see that the currency selector is enabled on your website. By enabling the template hints on again, we can see that its template is rwd/default/template/directory/currency.phtml, and its current code will look like this:

1
<?php if($this->getCurrencyCount()>1): ?>
2
<div class="currency-switcher">
3
    <label for="select-currency"><?php echo $this->__('Your Currency:') ?></label>
4
    <select id="select-currency" name="currency" title="<?php echo $this->__('Your Currency') ?>" onchange="setLocation(this.value)">
5
        <?php foreach ($this->getCurrencies() as $_code => $_name): ?>
6
        <option value="<?php echo $this->getSwitchCurrencyUrl($_code) ?>"<?php if($_code==$this->getCurrentCurrencyCode()): ?> selected="selected"<?php endif; ?>>
7
            <?php echo $_name ?> - <?php echo $_code ?>
8
        </option>
9
    <?php endforeach; ?>
10
    </select>
11
</div>
12
<?php endif; ?>

We’ll edit it to match our HTML, so the modified code will look like this:

1
<?php if($this->getCurrencyCount()>1): ?>
2
    <li class="dropdown">
3
        <a href="#" class="log"><img src="<?php echo $this->getSkinUrl('images/language.jpg'); ?>" alt=""></a>
4
        <ul class="subnav">
5
            <?php foreach ($this->getCurrencies() as $_code => $_name): ?>
6
                <li>
7
                    <a href="<?php echo $this->getSwitchCurrencyUrl($_code) ?>">
8
                        <?php echo $_code ?>
9
                    </a>
10
                </li>
11
            <?php endforeach; ?>
12
        </ul>
13
    </li>
14
<?php endif; ?>

Next, we’ll edit our welcome message to match our HTML design. For that we’ll have to go to System > Configuration/General/Design/Header/Welcome Text. After editing this, the header will look like this:

Header at the endHeader at the endHeader at the end

If you have followed all the steps correctly, I hope you can see much progress in your home page's looks. Now as we have partially edited the header section, we'll continue editing the header section in the next article, and we'll also edit the main slider in that article. 

Please do explain your experiences in the comments section!

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.