In this Tutorial, you’ll learn how to build a Custom homepage for your WordPress Theme using Page Templates: Complete with a featured content slider, and customizable Widgets.</p><divclass="toc" id="toc"><spanclass="label">Quick Nav:</span>

  • <ahref="#structure">Making a Template File
  • <ahref="#slider">Featured Content Slider
  • <ahref="#javascript">JavaScript
  • <ahref="#widgets">Custom Widget Areas in WordPress Templates
</div>Materials Needed:

  • <ahref="http://wordpress.org/">Wordpress
  • <ahref="http://macromates.com/">Text Editor
  • Note: any text editor will work.
A lot of people I have seen asking about how to make a custom landing page for their Wordpress website. In most standard themes, the homepage is a listing of recent posts.

What if instead you want to display a separate landing page? Maybe your site isn’t a typical run of the mill blog.


<aname="structure">
The Structure



To have a custom template page for Wordpress to recognize, simply create a new PHP file, I named mine custom_home.php, and at the very top when you call the header as you normally do, include this little snippet with the name of your custom page, so it should look like this,



Upload this file to your Theme Folder.

Now, when you’re adding or editing a page in WordPress, you should see a new Template in the Template Dropdown (inside the Attributes box).

You can use it now, but it wont do much for you just yet, since this is a blank file.

How you develop your template is completely up to you. In this tutorial, we’re going to craft something based off the illustration below:

<divclass="image-container" style="text-align:center;"><ahref="http://tutorial9.s3.amazonaws.com/wp-content/uploads/2010/03/layout.png" target="_blank"><imgsrc="http://www.tutorial9.net/wp-content/uploads/2010/03/layout.png" alt="Image Description" width="300" height="200" /></div>So go ahead and code this in HTML as you would any other page, keeping in mind that your header and footer should still be called with Wordpress,








<aname="slider">
Adding a Featured Content Slider



At the top of this page, we’re going to add a featured Content Slider using the awesomejQuery plugin <ahref="http://cssglobe.com/post/5780/easy-slider-17-numeric-navigation-jquery-slider" title="Easy Slider 1.7 - Numeric Navigation jQuery Slider | Css Globe">Easy Slider 1.7 by Alen Grakalic. I love his plugin because it is very easy to implement and built really well. Go ahead and download and unzip the file. Move the "easySlider1.7.js" file into your theme folder (if you’d like to stay organized, placing it in a /js/ folder makes sense)

Jump back into the featured_area div we created earlier, and build yourself a little list of links like so,



Notice that the links point to nowhere for now, you can put any address you like there. Also, the image path points first to the theme directory, where you will be uploading this very file you are making, so simply upload your images into an images folder in your themes root.

Now we need to add a bit of CSS to handle the slider and columns. So open up your style.css located in your theme’s root and find a cozy place to add some styling.

<divclass="note">Careful

If your theme already uses some of the ID’s and classes we’re trying to use, you may need to rename them. Otherwise, some styles may not work properly.

</div>#main_wrapper{width:940px;}#featured_area{width:720px;margin:10px auto;border:1px solid #333;-moz-border-radius: 10px;-webkit-border-radius: 10px;}#feature_slider{margin:0 auto;position:relative;width:700px;}#feature_slider ul, #feature_slider li{margin:0;padding:0;list-style:none;}#feature_slider li{width:700px;height:250px;overflow:hidden;}#column_wrapper {width: 940px;height: 200px;margin: 10px auto;}#column_wrapper .column {width: 290px;margin-left: 15px;float: left;border: 1px solid #333;-moz-border-radius: 10px;-webkit-border-radius: 10px;}This is assuming that you are using slides that are 700 pixels wide by 250 pixels tall, naturally you can adjust at your leisure. Also note, we are installing only basic functionality of what this slider is capable of, feel free to add to it by examining the downloaded plugin files. We also set a wrapper for the columns and gave them each a width of 290px and spaced evenly.


<aname="javascript">
The JavaScript




So we have a list of pictures and some styling to surround them, but they still wont do much without a final step. Open up header.php and inside the
area, we need to both include the slider script, and call the function. So somewhere below add the following;

What happens here is we call the plugin function and send in the arguments to override the default behavior, setting the slider to start automatically, and keep on going. We now have a sweet working content slider!


<aname="widgets">
Add Custom Widget Areas



Now you can guess what comes next, we have three nice columns just begging to be widget friendly, so I think we shall comply. Inside each column, we will include the code to let Wordpress know they are ready to accept widgets. To do this, we will need something like this:

This first checks to see if widgets are activated, and if so will call the appropriate widget based on the argument passed in, currently it calls a dummy widget named WIDGET_TITLE, we will change that. But for now go ahead and add one of these inside each of the column classes:

Widget Ready

This left_column is widget ready! Add one in the admin panel.

Widget Ready

This center_column is widget ready! Add one in the admin panel.

Widget Ready

This right_column is widget ready! Add one in the admin panel.

Take note that all three must have unique names in order to function properly. Additionally, don’t go try and play with this yet because it won’t work! We still need to tell Wordpress we are making up our own widget areas.

So go now and open up the scary functions.php file, found once again in the root folder of your theme files. Once open, we are going to add this ugly chunk of code, don’t worry though we will step through it.

if (function_exists('register_sidebar')) { register_sidebar(array( 'name' => 'Left Column', 'id' => 'left_column', 'description' => 'Widget area for home page left column', 'before_widget' => '', 'after_widget' => '
', 'before_title' => '', 'after_title' => '

' )); register_sidebar(array( 'name' => 'Center Column', 'id' => 'center_column', 'description' => 'Widget area for home page center column', 'before_widget' => '', 'after_widget' => '
', 'before_title' => '', 'after_title' => '

' )); register_sidebar(array( 'name' => 'Right Column', 'id' => 'right_column', 'description' => 'Widget area for home page right column', 'before_widget' => '', 'after_widget' => '
', 'before_title' => '', 'after_title' => '

' )); }Alright, so it looks nasty, but all that happens here is Wordpress sees that we are creating our own areas capable of being widgetized. First it checks if we are allowed to register new areas and then creates a couple of sidebar arrays. Don’t worry, they will not become sidebars, that is just the name. Inside the array we identify a few values such as the name of the widget area and a unique ID to assign it for CSS purposes and the like. The description is, well, a description and then the weird stuff. The before and after widget attributes open and close a div element, and use a Wordpress magic to make sure the class and id are unique to each. The title before and after set, optionally, what surrounds the user entered title of the widget. This places it inside a set of h4 tags.

Not too bad right? And we are almost done! Go ahead and call the footer in at the very bottom of your new custom home page, and this will close up this page for now, yay!


<aname="endgame">
The Endgame



Ok now grab your completed file, custom_home.php (if you named it same as mine) and if you have not already drop it into your theme root folder and lets make this happen. Log into your Wordpress Admin area and be sure the theme you want is activated. Create a new page and name it ‘Home’ then be sure to set its template to the one we just made, like this,

<divclass="image-container" style="text-align:center;"><ahref="http://tutorial9.s3.amazonaws.com/wp-content/uploads/2010/03/addNew.png" target="_blank"><imgsrc="http://www.tutorial9.net/wp-content/uploads/2010/03/addNew.png" alt="Image Description" /></div>Now head into the settings area and click on the ‘reading’ option. Up at the top where it asks you what the front page should display, click on static page, then choose your freshly made ‘Home’ page from the drop down menu.

<divclass="image-container" style="text-align:center;"><ahref="http://tutorial9.s3.amazonaws.com/wp-content/uploads/2010/03/setPage.png" target="_blank"><imgsrc="http://www.tutorial9.net/wp-content/uploads/2010/03/setPage.png" alt="Image Description" /></div>Only one more stop! Hit up the widgets panel now, and notice you have three of your own widget ready areas sitting on the side begging for some content.

<divclass="image-container" style="text-align:center;"><ahref="http://tutorial9.s3.amazonaws.com/wp-content/uploads/2010/03/addWidget.png" target="_blank"><imgsrc="http://www.tutorial9.net/wp-content/uploads/2010/03/addWidget.png" alt="Image Description" /></div>So comply! Fill them up and save it then visit you site and you should see an awesome custom home page now, enjoy it!