If this tutorial is not what you were looking for, you still have any questions, suggestions or concerns - feel free to let us know. Please help us to serve you better!

Your Name

Your Email

Your Message (required)

captcha

How to create category template

WordPress CMS allows you to create different category templates and modify the category page content and layout. Be default the category page displays a list of published posts in a chronological order starting from the most recent posts. To create category templates you should perform several steps.

Category template file name

Each category in WordPress has name, slug and ID. The category template file should contain category slug or ID. So for example if you want to create category template for the category "news" with ID: 5 the cateogry template file would be category-news.php or category-5.php

Custom category template

The default category.php file content is as follows:

<?php

get_header(); ?>

		<div id="container">
			<div id="content" role="main">

				<h1 class="page-title"><?php
					printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' );
				?></h1>
				<?php
					$category_description = category_description();
					if ( ! empty( $category_description ) )
						echo '<div class="archive-meta">' . $category_description . '</div>';
				get_template_part( 'loop', 'category' );
				?>

			</div><!-- #content -->
		</div><!-- #container -->

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Let’see what each part determines.

 

get_header(); ?>

Include the template header

 

<h1 class="page-title"><?php
printf( __( 'Category Archives: %s', 'twentyten' ), '<span>' . single_cat_title( '', false ) . '</span>' );
?></h1>

Defines the page title. Category name is used as a title.

 

$category_description = category_description();
if ( ! empty( $category_description ) )
echo '<div class="archive-meta">' . $category_description . '</div>';

Adds the category description to the page if it exists.

 

get_template_part( 'loop', 'category' );

Defines how posts will appear on the page

 

<?php get_sidebar(); ?>
<?php get_footer(); ?>

Include the template footer and sidebar

 

Using the WordPress core tags you can customize the template the way you need.

If you need more premium templates to choose from, check out wordpress themes categories.

How to create category template, 4.0 out of 5 based on 2 ratings