Categories

Featured templates

How to create category template

Rating: 2.9. From 7 votes.
Please wait...

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.

Best Designed Wordpress Themes
This entry was posted in WordPress, WordPress Tutorials and tagged archived_tutorial, category, create, custom, template, WordPress. Bookmark the permalink.

Submit a ticket

If you are still unable to find a sufficient tutorial regarding your issue please use the following link to submit a request to our technical support team. We'll provide you with our help and assistance within next 24 hours: Submit a ticket

Live Chat
We help you to choose the right product.