Archive for May, 2010
uDebug
Saturday, May 29th, 2010
It can keep track of the time when PHP executed certain sections of a PHP script.
The class can generate a XML document with the information of when PHP started and ended executing each section.
classes, rss
Classes | No Comments »
Bread crumb
Friday, May 28th, 2010
It looks at current page URL, removes a given base URL and split its parts separated by slashes.
The class generates bread crumb HTML links for each of URL parts.
classes, rss
Classes | No Comments »
Breadcrumb
Friday, May 28th, 2010
classes, rss
Classes | No Comments »
Easy Weather
Friday, May 28th, 2010
It can send a request to the weather.com site to retrieve weather forecast for a given location.
The class parses the forecast results and stores them in local cache files.
classes, rss
Classes | No Comments »
Quick Tip: The Multi-Column CSS3 Module
Friday, May 28th, 2010
For over six years, CSS3 columns have been available to us; yet, strangely, they’re rarely utilized. Because they currently are only supported in Mozilla and Webkit-based browsers, this means that – again – no support in Internet Explorer. But that’s okay! The world will not end if IE users see one longer paragraph. I’ll show you how to use this helpful module in today’s video quick tip.
Subscribe to our YouTube page to watch all of the video tutorials!
Prefer to watch this video on Screenr?
#container p {
-webkit-column-count: 3;
-webkit-column-gap: 10px;
-moz-column-count: 3;
-moz-column-gap: 10px;
column-count: 3;
column-gap: 10px;
}
- column-count: The desired number of columns for the element.
- column-gap: The padding between each column.
- column-rule: The divider for each column; can be used to specify a border.
- column-width: Used to specifically state the width of each column.
Please note that we must prefix each property with the -webkit or -moz, accordingly; so: -webkit-column-count.
Do you use CSS columns in your projects? If no, why not?
learn, php, rss, tutorials
PHP Tutorials | No Comments »
Magento for Designers: Part 4
Friday, May 28th, 2010
Magento is a stunningly powerful e-commerce platform. In this miniseries, we’ll learn how to get started with the platform, getting to know the terminologies, setting up a store and all related aspects of it and finally learn how to customize it to make it our very own.
In this fourth part, we’ll lay the groundwork for our theme which we’ll be building completely from scratch. Excited? Let’s get started!
The Full Series
- Part 1: Installation and Setup
- Part 2: Products, Taxes, Categories, Payment Gateways, etc.
- Part 3: Theming
- Part 4: Building the Theme
A Quick Recap
In the last parts, we learned how to get your Magento store from installed to ready for deployment including how to set up your products, product categories, taxes, shipping, payment gateways and many more.
We also took a look at the basics of Magento theming. We learnt the general idea behind Magento themes, the various terminologies behind it and the basic structure of a theme.
Goals for our Theme
Our goal for building this theme is fairly straightforward: to practically understand how to build a Magento theme. With that in mind, I’m going to keep the theme as simple as possible.
- Everything but the bare essential features stripped out
- No images other than the product images and the logo
- Single column to keep it visually simple
What are We Building Today?
Since the Magento coding process is reasonably complicated for someone used to WordPress, we’re going to take it extremely slow. Today, we’ll build just the core part our theme, the skeleton that gets used in each view of the site. I’ll also explain the general principle behind the process so we can move on to each individual view in future parts.
The source files, both the front end and back end, are included but try to not use it just yet. We’ll be defining just the core parts without defining what content is to be displayed, how it should be displayed and where the content is to be pulled from. So, if you try to use this right now, you’re going to see a bunch of gibberish since Magento pulls in all absent files from its default theme thus completely ruining our look. So my advice is, wait for a bit.
The Basic Template

The basic template looks like so. We have a generic logo up top along with a simple menu which lets the user access his account, wish list and cart along with letting him checkout or logout.
Below that, we have a utility bar that contains a breadcrumb style navigation to let the user know the contextual hierarchy of the site. We also let the user search through our store through the search input on the right.
The content area is currently empty since its contents will vary depending on which view Magento is loading. So we’ll keep is empty for now and handle it later when we’re building each individual page.
The footer is fairly generic with a link to report bugs and copyright information.
Step 1 – The HTML
We’ll first look at the HTML for the theme’s skeleton. I’m assuming you’re fairly fluent in HTML and CSS so I’ll skip to the more important parts.
<!-- Lumos!--> <!DOCTYPE html> <html lang="en-GB"> <head> <title>Cirrus - Magento Theme</title> <link rel="stylesheet" href="css/cirrus.css" /> </head> <body> <div id="wrapper" class="border"> <div id="header"> <div id="logo"><img src="images/logo.gif" /></div> <div id="hud"> <h3>Welcome, Sid</h3> <ul class="links"> <li><a href="#" title="My Account">My Account</a></li> <li ><a href="#" title="My Wish list">My Wish list</a></li> <li ><a href="#" title="My Cart">My Cart</a></li> <li ><a href="#" title="Checkout">Checkout</a></li> <li><a href="#" title="Log Out" >Log Out</a></li> </ul> </div> </div> <div id="utilities"> <div id="breadcrumbs">Home » State of Fear</div> <div id="header-search"><input type="text" class="border" value="Search our store" /></div> </div> <div id="content" class="product"> <h1>Content here</h1> </div> <div id="footer" class="border"> Help Us to Keep Magento Healthy - Report All Bugs (ver. 1.4.0.1) © 2008 Magento Demo Store. All Rights Reserved. </div> </div> </body> </html>
First up, note that I’ve wrapped everything under a wrapper div to make it easier to manage things. Also note that the header, content and footer section get their individual blocks.
The search input is fairly useless at this point. We’ll hook it up properly during when we’re integrating with Magento. Same with the various links. Currently, I’ve put them there as placeholders. Once we dig into Magento, we’ll get them working.
Step 2 – The CSS
* {
margin: 0;
padding: 0;
border: none;
outline: none;
color: #333;
font-family: "Lucida Sans Unicode", "Lucida Grande", sans-serif;
font-size: 14px;
list-style: none;
line-height: 1.3em;
}
a {
color : #7db000;
}
h1, h2, h3, h4 {
font-weight: normal;
}
h1 {
font-size: 32px;
margin-bottom: 10px;
}
h2 {
font-size: 24px;
margin: 10px 0 12px 0;
}
h3 {
font-size: 20px;
margin-bottom: 5px;
}
h4 {
font-size: 20px;
}
.border {
border: 1px solid #666;
}
/* Base Elements */
#wrapper {
width: 920px;
margin: 10px auto;
padding: 20px;
}
#header {
margin: 0 0 20px 0;
overflow: auto;
}
#content {
margin: 20px 0;
overflow: auto;
}
#footer {
padding: 10px;
border: 1px solid #E1E1E1;
background: #F3F3F3;
text-align: center;
}
/* Header content */
#logo {
float: left;
}
#hud {
float: right;
width: 320px;
height: 50px;
padding: 10px;
border: 1px solid #E1E1E1;
background: #F3F3F3;
}
#hud li a {
float: left;
font-size: 12px;
margin: 0 10px 0 0;
}
#utilities {
clear: both;
margin: 20px 0;
overflow: auto;
padding: 7px 10px;
border: 1px solid #E1E1E1;
background: #F3F3F3;
}
#breadcrumbs {
float: left;
}
#header-search {
float: right;
}
Nothing fancy here. Very basic CSS to place the elements in position and style it just a tiny bit. Let’s move on.
Step 3 – Creating our page.xml File
This part is a little tricky so stay with me here. Magento uses XML files to handle a page’s layout and also to define which elements are available to be rendered. The aim is that instead of mucking around with arcane code, you can just edit the XML file and be done with it without worrying about dependencies.
Each view/screen/module gets its own XML file along with a master file to define the general layout of the site. That master file is the page.xml file we’re going to create now.
The complete file for today looks like so. I’ll explain each bit part by part below.
<?xml version="1.0"?>
<layout version="0.1.0">
<default translate="label" module="page">
<label>All Pages</label>
<block type="page/html" name="root" output="toHtml" template="page/1column.phtml">
<block type="page/html_head" name="head" as="head">
<action method="addCss"><stylesheet>css/cirrus.css</stylesheet></action>
</block>
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>
<block type="core/template" name="top.search" as="topSearch"/>
</block>
<block type="core/text_list" name="content" as="content"/>
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml"/>
</block>
</default>
</layout>
Disregard the initial XML and layout version declarations. They’re of no significance to us now.
<block type="page/html" name="root" output="toHtml" template="page/1column.phtml">
First, we create a master block for all the data. Consider this the equivalent of the wrapper DIV element we used in our HTML. Next, we instruct it to use page/1column.phtml as the template for our page. Don’t worry, we haven’t created the file yet. We’ll do so later in this tutorial.
<block type="page/html_head" name="head" as="head">
<action method="addCss"><stylesheet>css/cirrus.css</stylesheet></action>
</block>
Next, we define the elements to be included in the head section of the page. Magento, by default, includes a load of CSS and JS files but we won’t be requiring any of their functionality today. So, we’ll just include our CSS file.
<block type="page/html_header" name="header" as="header">
<block type="page/template_links" name="top.links" as="topLinks"/>
<block type="page/html_breadcrumbs" name="breadcrumbs" as="breadcrumbs"/>
<block type="core/template" name="top.search" as="topSearch"/>
</block>
We’re defining what goes into the header of our site. We want the menu/links at the top as well as the breadcrumbs and the search.
<block type="core/text_list" name="content" as="content"/>
We’ll need the content part, of course, so we’re including the content part. We won’t define anything about this section here since Magento just loads up all the necessary content into this block.
<block type="page/html_footer" name="footer" as="footer" template="page/html/footer.phtml"/>
And finally, we’ve included our footer. We also tell Magento where to load its template from.
You’re probably wondering why we specify a template path for some blocks whilst omitting it for others. It’s a rather higher level topic but did you note that each block has a type attribute? When it’s type matches one of those predefined by Magento, you need not specify a template. It’s auto loaded. Nifty, no?
And with this, our base page.xml file is complete.
Step 4 – Creating our Skeleton Template
Ok, now that we’ve specified our layout we can move on to creating the 1column.phtml file that we specified in the XML earlier.
This file is nothing but a skeleton template which calls in the header, content area and footer as needed. Our file looks like so:
<!-- Lumos!--> <!DOCTYPE html> <html lang="en-GB"> <head> <?php echo $this->getChildHtml('head') ?> </head> <body> <div id="wrapper" class="border"> <?php echo $this->getChildHtml('header') ?> <div id="content" class="product"> <?php echo $this->getChildHtml('content') ?> </div> <?php echo $this->getChildHtml('footer') ?> </div> </body> </html>
This is pretty much our original HTML file except that we use the getChildHtml method to acquire each block’s content. The template needs to be pretty page agnostic as it’s the master page from which each page is rendered.
Step 5 – Creating the Templates for our Blocks
Now comes the slightly hard part: cutting up our core HTML blocks by functionality, creating the required templates files for each functionality and then populating those files.
We’ll tackle each in order of appearance
head Section
getChildHtml(‘head’) maps directly to page/html/head.phtml. Our file looks like so:
<title><?php echo $this->getTitle() ?></title>
<link rel="icon" href="<?php echo $this->getSkinUrl('favicon.ico') ?>" type="image/x-icon" />
<link rel="shortcut icon" href="<?php echo $this->getSkinUrl('favicon.ico') ?>" type="image/x-icon" />
<?php echo $this->getCssJsHtml() ?>
<?php echo $this->getChildHtml() ?>
<?php echo $this->getIncludes() ?>
You’ll see that we let Magento dynamically create the titles. Other than that, do notice the getCssJsHtml method being called. This method imports all the CSS and JS files that we specified in the page.xml file.
Page Header
getChildHtml(‘header’) maps directly to page/html/header.phtml. Our file looks like so:
<div id="header">
<div id="logo"><a href="<?php echo $this->getUrl('') ?>" title="<?php echo $this->getLogoAlt() ?>" class="logo"><img src="<?php echo $this->getLogoSrc() ?>" alt="<?php echo $this->getLogoAlt() ?>" /></a></div>
<div id="hud">
<h3>Welcome</h3>
<?php echo $this->getChildHtml('topLinks') ?>
</div>
</div>
<div id="utilities">
<?php echo $this->getChildHtml('breadcrumbs') ?>
<?php echo $this->getChildHtml('topSearch') ?>
</div>
We use Magento’s API to acquire the logo first. Then to further modularize things, we get the HTML for the breadcrumbs, links and the search function.
Note that the name is purely semantic. As you can see, you’re not limited to the header in it’s purest, strict technical sense. You can also tack on other elements as needed.
Page Footer
getChildHtml(‘footer’) maps directly to page/html/footer.phtml as specified in the XML file. Our file looks like so:
<div id="footer" class="border">
<?php echo $this->__('Help Us to Keep Magento Healthy') ?> - <a href="http://www.magentocommerce.com/bug-tracking"
onclick="this.target='_blank'"><strong><?php echo $this->__('Report All Bugs') ?></strong></a>
<?php echo $this->__('(ver. %s)', Mage::getVersion()) ?> <?php echo $this->getCopyright() ?></address>
</div>
With the footer, you’re free to include any info you deem fit. I just included the default content since I couldn’t think of anything clever to say there.
With the core elements finished, we can move on to the smaller functional blocks specified in the header section now i.e. the breadcrumbs, links and the search feature.
Top Links
getChildHtml(‘topLinks’) maps directly to page/html/template/links.phtml. Our file looks like so:
<?php $_links = $this->getLinks(); ?>
<?php if(count($_links)>0): ?>
<ul class="links"<?php if($this->getName()): ?> id="<?php echo $this->getName() ?>"<?php endif;?>>
<?php foreach($_links as $_link): ?>
<li<?php if($_link->getIsFirst()||$_link->getIsLast()): ?> class="<?php if($_link->getIsFirst()): ?>first<?php endif; ?><?php if($_link->getIsLast()): ?> last<?php endif; ?>"<?php endif; ?> <?php echo $_link->getLiParams() ?>><?php echo $_link->getBeforeText() ?><a href="<?php echo $_link->getUrl() ?>" title="<?php echo $_link->getTitle() ?>" <?php echo $_link->getAParams() ?>><?php echo $_link->getLabel() ?></a> <?php echo $_link->getAfterText() ?></li>
<?php endforeach; ?>
</ul>
<?php endif; ?>
I know it looks a little complicated, but all it does is loop through an array of links and then spit it out, whilst adding a special class if it’s the first or last item in the list. If you’d prefer, you can scrap all this, and just hard code your top menu.
Breadcrumbs
getChildHtml(‘breadcrumbs’) maps directly to page/html/breadcrumbs.phtml. Our file looks like so:
<?php if($crumbs && is_array($crumbs)): ?>
<div id="breadcrumbs">
<?php foreach($crumbs as $_crumbName=>$_crumbInfo): ?>
<?php if($_crumbInfo['link']): ?>
<a href="<?php echo $_crumbInfo['link'] ?>" title="<?php echo $this->htmlEscape($_crumbInfo['title']) ?>"><?php echo $this->htmlEscape($_crumbInfo['label']) ?></a>
<?php elseif($_crumbInfo['last']): ?>
<strong><?php echo $this->htmlEscape($_crumbInfo['label']) ?></strong>
<?php else: ?>
<?php echo $this->htmlEscape($_crumbInfo['label']) ?>
<?php endif; ?>
<?php if(!$_crumbInfo['last']): ?>
<span>» </span>
<?php endif; ?>
<?php endforeach; ?>
</div>
<?php endif; ?>
As with before, it merely loops through the crumbs to render the text. The naughty bits in there checks whether the crumb is a link, to format it as such, and check whether it’s the final element so it doesn’t have to render a separator. There’s nothing else to this block.
Search
getChildHtml(‘topSearch’) maps directly to catalogsearch/form.mini.phtml. Our file looks like so:
<div id="header-search">
<form id="search_mini_form" action="<?php echo $this->helper('catalogsearch')->getResultUrl() ?>" method="get">
<input id="search" type="text" name="<?php echo $this->helper('catalogsearch')->getQueryParamName() ?>" value="<?php echo $this->helper('catalogsearch')->getEscapedQueryText() ?>" class="input-text border" />
</form>
</div>
Magento does all the weight lifting here. All you need to do is call the proper API method for the URLs and such.
If you’ve noticed that the string passed on to the getChildHtml method maps directly to the as attribute used in the page.xml file, then congrats, you’re an astute reader and you get a delicious cookie!
What We’ll be Building in the Next Part

Now that we’ve built a very strong core, we can now move on to building the individual views of the store. In the next part, we’re going to build one of the core views of any store, the product view. Stay tuned!
The Last Word
And we are done! Today, we took the first step in creating our custom Magento theme, Cirrus. Hopefully this has been useful to you and you found it interesting. Since this is a rather new topic for a lot of readers, I’ll be closely watching the comments section so chime in there if you’re having any doubts.
Questions? Nice things to say? Criticisms? Hit the comments section and leave me a comment. Happy coding!
learn, php, rss, tutorials
PHP Tutorials | No Comments »
Core class
Thursday, May 27th, 2010
It can automatically load other framework classes when it is accessed a variable of the class that starts with a capital letter.
classes, rss
Classes | No Comments »
Storage
Thursday, May 27th, 2010
It can take variable values and store them in files with given names.
The class can also do the opposite, i.e. retrieve variable values from files.
The variables can be scalar, or objects or arrays, provided the class or a sub-class defines functions to serialize and unserialize the variable values.
classes, rss
Classes | No Comments »
WordPress 3.0 Release Candidate
Thursday, May 27th, 2010
As Matt teased earlier, the first release candidate (RC1) for WordPress 3.0 is now available. What’s an RC? An RC comes after beta and before the final launch. It means we think we’ve got everything done: all features finished, all bugs squashed, and all potential issues addressed. But, then, with over 20 million people using WordPress with a wide variety of configurations and hosting setups, it’s entirely possible that we’ve missed something. So! For the brave of heart, please download the RC and test it out (but not on your live site unless you’re extra adventurous). Some things to know:
- Custom menus are finished! Yay!
- Multi-site is all set.
- The look of the WordPress admin has been lightened up a little bit, so you can focus more on your content.
- There are a ton of changes, so plugin authors, please test your plugins now, so that if there is a compatibility issue, we can figure it out before the final release.
- Plugin and theme *users* are also encouraged to test things out. If you find problems, let your plugin/theme authors know so they can figure out the cause.
- There are a couple of known issues.
If you are testing the RC and come across a bug, you can:
- Report it on the wp-testers mailing list
- Join the dev chat and tell us live at irc.freenode.net #wordpress-dev
- File a bug ticket on the WordPress Trac
We hope you enjoy playing with the 3.0 RC as much as we’ve enjoyed making it for you. Enjoy!
rss
Uncategorized | No Comments »
Lucky Seven
Thursday, May 27th, 2010
Has it really been seven years since the first release of WordPress? It seems like just yesterday we were fresh to the world, a new entrant to a market everyone said was already saturated. (As a side note, if the common perception is that a market is finished and that everything interesting has been done already, it’s probably a really good time to enter it.)
The growth over the past year has blown me away. Since our last birthday we’ve doubled theme downloads to over 10 million, and doubled plugin downloads to 60 million. Most importantly, we continued to grow the development community to 1,528 people active on Trac and 13 committers, both numbers the highest in the history of WordPress.
That’s 1,528 people pouring their hearts and souls into GPL software we all own, we all build on, we can use as we please, we can all make better. We’ve evolved from a simple script to a web platform.
We’re on the cusp of version 3.0, with a release candidate coming out any minute now.
If you’d like to celebrate WordPress’s birthday with us — tell a friend! Help them upgrade their blog or find the perfect theme. Talk about how WordPress is built by and for a community. Drop in to help test 3.0, including all the plugins you use. Write something to take advantage of the new 3.0 features, or teach your friends how to. If you buy any themes or plugins, make sure they’re GPL or compatible just like WordPress. We’ve got a long road ahead of us, it’s important that we not forget that Open Source got us this far, and is the only way we’re going to get to the next level. The whole of what we can build together is far greater than the sum of our parts. Spread the good word.