P. 1
Building WordPress Themes From Scratch

Building WordPress Themes From Scratch

|Views: 350|Likes:

More info:

Published by: Pedro Teixeira Carballo on Aug 29, 2012
Copyright:Attribution Non-commercial


Read on Scribd mobile: iPhone, iPad and Android.
download as PDF, TXT or read online from Scribd
See more
See less





Next up, we’re going to create a general archives page. You should

note that this will display links to month and category archives, not

actual posts, which could be done by creating an archive.php

template page. However, our index.php template is handling that.

Also, this is going to be a page template so we’ll need to create a

page in WordPress that uses the template. WordPress does not

have a reserved “Archives” page template.

Create a fle named page-archives.php39

and place it in the

/director/ theme. Next, we’ll start the fle off with this text:


* Template Name: Archives



Our frst few lines tell WordPress that this is a page template

named “Archives,” which WordPress will use when a user is creat-

ing or editing a page. The rest should look familiar since it’s every-

thing before the Loop on the page.php template, with the addition

of the CSS class .archives after .left-col. This will apply some

special CSS to our archives page.

Next, we’ll want to add in the information for our archives. Since

we’re not pulling any direct content from WordPress, we do not

need the Loop. Instead, we’ll be using two other template tags:

wp_get_archives() – This will return a list of posts orga-

nized by date, based on the value of an argument named

“type”. The value can be: daily, weekly, monthly, yearly,


In some themes, developers will just name this archives.php. I’m following the
convention that any page template has the prefx page- .

Converting HTML to a WordPress Theme


postbypost, and alpha. The only difference between

postbypost and alpha is that postbypost sorts by date,

and alpha sorts by title.40

wp_list_categories() – This function will return a list of

category links based on the criteria you send it. You can

customize things like which categories to display, how to

display them, if you want to include a count, and more.41

We’re going to use these with what are mostly the default settings.

Starting on the next line of archives.php, add this:

Archives by Month:

Archives by Subject:

As you can see, we aren’t using too many custom settings for

either function here. With wp_get_archives(), we’re calling the

monthly archives, and for the rest, we are using the defaults.42


wp_list_categories(), again, we are primarily using the default

settings. However, we are making a couple of notable changes.

The frst is that we aren’t displaying the categories hierarchically.

By default, child categories would display as nested unordered

lists under their parents. For display purposes, we’ve set this to

false (or 0). There is also an argument called title_li. By default

this argument will make the frst list item the title (which is “Cat-

egories” unless otherwise noted) and make all of the categories a

nested list. By setting title_li to nothing, the categories become

the top-level list.





Converting HTML to a WordPress Theme


We’re going to round out our template using the same familiar:

We’re done with the page-archives.php template! Once you

create a page in the WordPress admin panel and apply the Archive

template, you will end up with something like this:

You're Reading a Free Preview

/*********** DO NOT ALTER ANYTHING BELOW THIS LINE ! ************/ var s_code=s.t();if(s_code)document.write(s_code)//-->