Create a Category Page Template with the Twenty Eleven Theme

The basics of this should work with about any WordPress theme, but the Twenty Eleven theme is the newest default theme for WordPress. With all the great features it has out of the box, I decided to activate it here. Only a few minor adjustments were made to fulfill what I wanted it to do. The biggest change was making a page that would list all of my tutorials. In the past, I’ve put this list in the sidebar, but have since decided to run the site without a sidebar(at least for now). Here’s how I made the page template.

First up, I copied my archive.php file, and named the copy category-tutorials.php. The first change I made to my new template was place this code at the top.

<?php
/*
Template Name: Category-Tutorials
*/
?>

This code is what will make the new page template show up as a template option, but more on that later.

In Twenty Eleven, the archive.php template has a ‘page header’. I left that. So, from the closing </header> tag all the way down to the closing content div – </div><!– #content –>, is the WordPress loop. I replaced the loop with this:

<ul class="category">

	<?php $archive_query = new WP_Query('cat=7&showposts=1000');
	while ($archive_query->have_posts()) : $archive_query->the_post(); ?>

	<li><a href="<?php the_permalink() ?>" rel="bookmark" title="Permanent Link to <?php the_title(); ?>"><?php the_title(); ?></a></li>

	<?php endwhile; ?>
</ul>

You’ll notice in the code, my WP_Query calls for “cat=7″, which is category ID 7(my Tutorials category ID). Then it calls for “showposts=1000″, so that it will list ALL the posts in this category. Of course you would need to replace the 7 with the category ID  that you are making this page for.

One other change I made, was in the “page-title” code. I changed the word “Blog Archives” to “Tutorials”. You’ll have to glance over the code to find it. This gives the page a heading…Tutorials.

Save that, and the template is done. Upload to the Twenty Eleven theme folder.

All that’s left at this point is to create your page in the WordPress admin. Go to Pages > Add New, and Create a new page. I named mine Tutorials. On the right side of the screen there is a drop down where you can choose a custom page template. I chose my new template out of the drop-down box, and published.

That’s it! All information was gained from the WordPress Codex plus a couple of Google searches.

You can download a copy of mine here.

4 thoughts on “Create a Category Page Template with the Twenty Eleven Theme

  1. You don’t have to create a page template to display a list of category posts. It’s simpler to just duplicate the category.php file in the Twenty Eleven directory and name it category-tutorials.php.

    WordPress is smart enough to recognize that’s the template to use for displaying that categories posts because of the template hierarchy.
    http://codex.wordpress.org/Category_Templates

    • Dan, I understand what you’re saying. But, the only way I was able to get the page to list only the post titles, was the way I did it.

    • indeed much to complicated just copy the category file rename it like this catgory-(id from your category).php and if you like add the category link to your menu and hops you have a nice category page

      cheeeeeers

Comments are closed.