Standing on the Shoulders of Giants

lifehackerFor this blog I want to talk about, how I went about designing my theme in a bit more detail. I have touched upon this briefly before, but in this post I will be more specific.

Standing on the Shoulders of Giants essentially means, building upon work that has already been done. You don’t always have to create something that is entirely new and inventive. OK it’s not bad if you can come up with something that is just that. Butt more often than not, you will waste your time
and money doing something that other people have already done.

When I start planning for a project I always try and get a sense of what is out there already. But I also do this frequently throughout the development and design process. If I run into a situation or a problem, where I need a solution, I will look around and see how others have solved it.

In my design I wanted to find the best place for my navigation and how it should be implemented. I specifically looked at the search bar, how prominent it should be? how important would it be for my users. All this would take months to research if I had to do it on my own.

Rather than do that, I had a look at other collaborative blog designs to see how they used the search bar. These blogs are some of the most popular on the web, so I trusted them to give me the solution. It turns out that they ALL had the search bar very very near the top of the page. I effectively decided to build my design around the search box, and made that together with the categories, the absolute first priority of the design.

WordPress Search Box

WordPress have two search boxes that can be used. You can hard code the search box into your theme, or you can use a search widget. The difference is essentially that widgets can be controlled
by the user, and the hard coded search bar is controlled by me. Because this feature is so prominent for this theme, I decided to hard code this search bar into the theme. It is always good to give the user control, but in this instance I trusted my own judgement to be the best thing for this particular theme.

searchform

Luckily WordPress already provide a search form that calls the database and searches through all the post in the database. This comes with all default Wrodpress Themes and the php files is called ‘searchform.php’. Now to include that in the coding of your theme, you use the php include statement. You can then call the php file by using:<?php include (TEMPLATEPATH . '/searchform.php'); ?>

Breaking that apart; The include statement tells the server to include a particular page here. The between the brackets you tells the server exactly which page to include. Here we have provided a URL that uses the TEMPLATEPATH function that is build into WordPress. When this is parsed by the server WordPress exchanges the word ‘TEMPLATEPATH’ with the absolute path, to the directory in which your theme is placed. The in this directory the server looks for the files called ‘searchform.php’, and then include all the code from this file, into the current page as XHTML code.

The alternative is to just hand code the snippet from the searchform.php file into your current php file. But the advantages with having a separate file for the search bar, is that you only have to type in one line of code every time you want to use it. This makes it easy to reuse the search form over many pages. And equally handy is it if you want to change some of the code, you don’t have to go back and change 5-6 pages or more, you just change that single searchform.php file and it will automatically update on the other pages when it’s parsed by the server again.

/Kasper – on Twitter and Delicious

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: