How to Make WordPress Category Templates


Do you want to make your own WordPress category page layouts?

It’s common to use different templates for categories, tags, custom post types, and taxonomies on WordPress websites.

We’ll show you how to make category templates in WordPress in this article.

You can add specific features to category pages by creating category templates.

You can, for example, allow users to subscribe to categories, upload category images, display category descriptions, and customize each category’s layout.

Why Do You Need WordPress Category Templates?

WordPress creates separate pages for each of your categories. You can see them by going to a URL such as:

http://example.com/news/category/

The category title is highlighted in these templates, and the category description is displayed below it. The majority of popular WordPress themes include built-in templates for showcasing category pages.

Some themes, however, may not be able to handle this well, or you may wish to customize your category pages. This is where you’ll need to create WordPress category templates.

Let’s take a look at how to make WordPress category templates.

WordPress Category Pages Template Hierarchy

The powerful templating system in WordPress allows you to create different templates for different sections of your website.

WordPress looks for a template in a pre-defined hierarchical order when displaying any page.

â’ category-id.php â’ category.php â’ archive.php â’ index.php â’ category-slug.php It looks for templates in this order to display a category page:

Using the category slug, WordPress will look for a template that is specific to that category. The category-design.php template, for example, will be used to display the Design category.

If a category-slug template isn’t found, WordPress will look for a template with a category id, such as category-6.php. It will then look for the generic category template, which is usually named category.php.

Finally, the category will be displayed using the index.php template. WordPress will look for a generic archive template, such as archive.php, if there is no generic category template present.

Our guide to WordPress template hierarchies can be found here.

Using WordPress to Create a Category Template for Your Theme

Let’s look at a typical category.php template first.

Let’s pretend you have a category called “Design” with the category-slug “design” that you want to display differently than the others.

To do so, you must first create a template for that category. To access the theme editor, go to Appearance » Theme Editor. Click on category.php from the list of theme files on your right; if you don’t see a category.php file, look for archive.php.

We recommend that you look up the framework you’re using. If you can’t find either of these templates, you’re probably using a WordPress Theme Framework, in which case this tutorial won’t help you.

This file should be saved as category-design.php. If you find the files listed above, copy and paste the contents of category.php into a text editor such as Notepad.

Connect to your WordPress hosting using an FTP client, then upload your category-design.php file to your theme directory at /wp-content/themes/your-current-theme/.

Any changes you make to this template will now only appear on the archive page for this category.

You can create templates for as many categories as you want using this method. The categories section of the WordPress admin area is where you’ll find category slugs. Simply name the file category-category-slug.php.

An example of a category-slug.php template can be found here. We’ve used the same template as category.php with a few minor tweaks.

Also, instead of using?php the_content();?>, we’ve used?php the_excerpt();?>. We can add the title, description, and any other details manually because we already know what category it will be used in.

See why we think using a post summary or excerpt rather than the entire post is a good idea.

If you don’t want to use the category-slug template, you can create a template for a specific category ID with the category-id template. In WordPress, here’s how to find a category ID.

For a Category, Conditional Tags are used.

When creating templates for your theme, think about whether you really need a separate template for each task.

In some cases, the changes you want to make are simple enough to accomplish with conditional tags inside a generic template, such as category.php or archive.php.

Many conditional tags are available in WordPress, which theme authors can use in their templates.

You can change your templates to display different output if the condition is met by using this conditional tag. is_category() is an example of a conditional tag.

As an example, suppose you have a “Featured” category for featured posts.

To do so, place this code after?php if ( have_posts() ) :?> in the category.php file. You’d like to add some additional information to the category archive page for this category.

Using Beaver Themer, create a Category Template

Beaver Themer gives you the ability to design layouts for your theme. You can pick and choose which categories to use the template in, and then edit it with a drag-and-drop tool.

Go to Beaver Builder » Themer Layouts » Beaver Builder » Themer Layouts » Beaver Builder » Themer Layouts » Beaver Builder » The Create a new page.

You’ll need to give it a title and then choose your category from the ‘Location’ drop-down menu.

Then, using Beaver Builder’s drag-and-drop editor, you can customize your category layout page to your heart’s content.

When you’re finished, click Done, then choose Publish to apply your category template.

You can now view the category template in action on your website.

You might also be interested in our comparison of the best drag-and-drop WordPress page builders for creating custom layouts, as well as our tutorial on how to create a membership site with content restrictions based on categories. We hope you found this article helpful in learning how to make WordPress category templates.

You can also find us on social media sites such as Twitter and Facebook. Please subscribe to our YouTube Channel for WordPress video tutorials if you enjoyed this article.

    How to Fix the WordPress Error Establishing a Database Connection

    How to Transfer Your Blog from WordPress.com to WordPress.org Correctly

    Step-by-Step Instructions for Starting Your Own Podcast

    Why is it so important to build an email list today? (6 Reasons)

    Editorial Staff Information

    Over 1.3 million readers around the world rely on it. WPBeginner’s Editorial Staff is a group of WordPress experts led by Syed Balkhi.

    I’d like to make the same custom page for all categories, but I don’t want to do it one at a time. What’s the best way for me to get this? If I add a new category in the future, I want the new category to have the same template as the old one.

    There is only one category.php template that must be created; this category template will be used in any category archive that you create.

    Greetings – It’s a great tutorial, but I’m trying to display a specific category and its subcategories on a single page. How do I do that?

    You should read https://kiuz.it/wp-tutorials/display-subcategories-on-category-pages-in-wordpress/ for more information.

    Thank you very much! This is extremely beneficial!

    Thank you very much.

    Thank you so much for saving my time.

    Constant Contact will be used by my church to send out a newsletter. I’m asking this question because it’s the most relevant to what I’m looking for. There are both short and longer articles in our current newsletter. I now want to remove the H1 from the header, but since the header is called from the post page, the only way I can get the result I want is to create a custom page/post that does not call header.php but instead includes the contents of header.php in my custom post page. The header image has been changed by Unique Headers. I’d like to include short excerpts from longer articles in the newsletter, along with a link to the full article. I’m thinking about making a custom footer. To that end, I’ve made a category-newsletter and used a plugin to do so.

    How do I do it without making a mistake?

    This is something I see far too often in this community: an explanation for advanced users or developers that is of little or no use to beginners. I mistook this for WP BEGINNER – it’s hardly a beginner’s tutorial and was of no use to me at all. If you’re a seasoned coder, this is an excellent tutorial for creating templates.

    Is there anyone who can assist me with the code? Hello, this is a fantastic tutorial. I’d like to set a limit of five posts per page and include page numbering.

    I had gone through every php I could find and had scoured my FTP/control panel for categories. I hope this comment is helpful to anyone else who is using the free version of the plum theme and wants to know how to do this in ftp. Thank you so much for taking the time to write this article – Despite the fact that the advice given here essentially stated that it couldn’t help and that I wouldn’t find it useful, it did encourage me to look at the content.php file in the theme’s ‘framework’ directory. I was looking for the categories for my personal blog site and couldn’t seem to find them.

    As a result, this article is ideal for me because I require them. My theme didn’t come with a template for categories, tags, or anything else.

    Is it better to do this in a child theme so that custom changes don’t get lost when the theme is updated?

    Some code had to be added to functions.php as well. Instead of having all category-slug.php among all other theme php files like header.php, footer.php, index.php, and so on, I wonder if it would be better to have all category-slug.php among all other theme php files like header.php, footer.php, index.php, and so on. For category-specific Custom Single Post page templates, create a separate folder called “single” and place all single templates inside, such as single-category-slug.php. + the general single.php. Is it possible to use the same technique for Category page templates, such as putting all category-slug.php and general category.php in a map called “category”?

    That is extremely beneficial. I’m not sure how I’m going to do it. Thank you… What if I want a page that shows all of the posts from three of my five categories?

    Hello, Rami.

    You can create a custom archive page and then use the Display Posts Shortcode plugin or write a custom WP Query.

    Very helpful, and it saved my day!

    how to make a multi-category template with a variety of layouts

    Nice tutorial; I appreciate the significant investment in both the WordPress tutorial and OptinMonster. You forgot to echo the single_cat_title( ”, false ); in the category template. However, I’d like to draw your attention to something in the tutorial:

    It should be as follows:

    Sub-category:

    Thank you.

    When I use this template, the Dashboard only shows the maximum number of posts, which is ten. When I add query_posts(‘posts_per_page=50’); to the beginning of the Loop, posts from a different category appear in my selection. When I choose a category, I want to see all of the posts in that category, not just the top 10. Do you have any suggestions?

    I haven’t been able to come up with a better solution. Instead of text, I’d like an image of the post to appear beneath the blog title. Hello, my theme includes a category.php file. Thank you very much. Sir, please assist me. When I view it, however, it only displays the title and a brief summary of the post. I’m a WordPress newbie.

    Hello there,

    I’m having a hard time figuring out how to use “Image” instead of “text” in the category page. Is there anyone who can assist me here?

    This is my category.php file.

    Please send me an email with instructions on how to fix this. Please accept my sincere gratitude.

    Put this code where you want the featured image to appear.

    You might also be interested in our WordPress tutorial on how to add a featured image or post thumbnail.

    However, when I try the first code, it fails. In category.php on line 22, there is a parse error: unexpected ‘’. Thank you for sharing this useful information. It makes a mistake.

    The second error occurs on line 31, and it is the same as the first.

    I double-checked everything. So, what happened?

    The closing tags?> on lines 21 and 29 are missing, resulting in an error on the following line: I realize I’m a little late, but I’m hoping it will be useful to someone.

    if ( category_description() ):?> 21 29 if ( have_posts() ) the_post();?>

    The code has been corrected. Thank you for letting us know.

    Hi, on line 30, just add?> after while ( have_posts() ): the_post();

    There is no archive or category php that I can find. Is it possible to start with index.php and modify it from there to create a custom category page? Divi 2.1.4 is the version I’m using.

    I’m not sure how I’d get all of my category page templates to show up on one page. I have three different category templates that look great on each individual category page, but I’d like to see them all on one page.

    Thank you for letting us know. We were able to fix the code.

    Thank you so much for your time and effort; this blog is extremely helpful!

    On line 29, you didn’t close the while loop?> Your example code helped me solve my problem.

    29 the_post(); while ( have_posts() )

    Please take a look at line 41 to see how the loop is closed.

    On line 40, it is not closed.

    When viewing the outputted source, there isn’t even an opening html tag. I literally copied and pasted your code (removing the line numbers), saved the file, and tested it, and I get a completely blank page. I’m attempting to create a theme for the first time, and I’ve gotten stuck on the category template. Has anything changed since the release of WordPress 3.9?

    Yes, same issue – copy and paste – blank page – no hidden html at all

    Hello there,

    @ Category Archives page — I’m working on a child theme and want to show a specific image alongside the category description.

    If the category is cooking, SHOW + description + post list; if the category is tutorial, SHOW + description + post list; SHOW + description + post list; SHOW + description + post list; SHOW + description + post list; SHOW + description + post list; SHOW + description + post list; SHOW + description + post in other words, If the category is Poetry, then

    I’m aware that the IF-Condition can be placed in the category.php >> Archive header.

    However, my list is quite long — nearly 20 categories — and I don’t want to clog up the category.php file.

    Is it possible to make a call to category.php from a custom function (in myfunc.php)?

    Thank you very much.

    This is strange; some of my text in the comment is missing, so I’m reposting it here.

    if tutrial is a category, TEACHER IMAGE + DESCRIPTION + POST LIST SHOW TEACHER IMAGE+ DESCRIPTION + POST L SHOW CHEF IMAGE+ description + post list if the category is cooking. in other words, SHOW QUILL IMAGE+ description + post list if the category is Poetry.

    Yes, you can create a function in functions.php that checks for all categories and then call it from your category.php file. Dear Deepa,

    I’d like to display only one category per page, but all posts from all categories appear on all pages. Hello there! I’m having trouble with the theme I’m working on. How can I display only one category per page without having to create a separate page for each page that specifies the category name?

    In WordPress, you can use conditional tags or simply add your categories to the navigation menu.

    I need to change the style of the most recent post in the selected category. Is it possible to include a function like showposts in this loop? I am a designer who has recently joined the development team.

    In WordPress, here’s how to show recent posts from a category.

    Only the archive.php file exists in the parent theme. I want an archive.php file in my child folder for my Archives widget, and a category.php file for my Category widget. This appears to be simple, but I’m having trouble with it. Thank you very much. I copied the archive.php code and saved it as category.php in a blank php file. Both are still defaulted in archive.php. I’m working on a child theme based on a parent theme. Is there something I’m overlooking?

    Is it possible to open the category.php file in the Appearance » Editor? Also, make sure you’ve followed our guide to creating child themes to ensure you’ve done it correctly. There’s nothing you’re missing. When a user visits a category page, category.php should take over. Make sure you didn’t save category.php as category.php.txt by accident. WordPress, for example, might not be able to recognize the category.php file. This may occur for a variety of reasons.

    Thank you very much. Is it necessary to include the category.php file somewhere? Hello there. With the Appearance>Editor, I can open category.php.

    It should be included in your main theme or a child theme.

    The file is saved alongside the rest of my site’s working files in my child theme. With the Appearance>Editor, I can open category.php. Hello there. Is it necessary to include it in the functions.php file for WordPress to use category.php rather than archive.php?

    Thank you so much for saving my time.

    It was extremely beneficial. Thank you for a fantastic article.

    I need a central location for all videos, as well as a page that lists videos by category. What is the best way to present them? I’ve created a custom post type called “video” as well as a custom taxonomy called “video_categories.”

    archive-videos.php – This is the “home” page for all videos in all categories. a category listing page called taxonomy-video_categories.php

    There must be a better way, in my opinion. This is what I’m considering. At the moment, the code in these two files is identical, resulting in duplication.

    Thank you for taking the time to share your story.

    This is an excellent tutorial.

    The concept of creating different designs for each category page appealed to me. Could you please tell me how I can create a specific design for a post in a specific category?

    For example, all posts in the category “Design” will have a specific design format and background, among other things.

    I’d be grateful for any links that could point me in the right direction.

    In your single.php file, you’ll need to use a conditional statement.

    and will serve as a useful reference point. I’ve saved it to my favorites. and being diverted from more important tasks. Thank you very much! It’s not that I can’t do it; it’s just that I keep forgetting… This is something I’ve wanted to do for a long time. Your post serves as an excellent reminder…

kiuz
Logo
Enable registration in settings - general