{"id":72368,"date":"2012-02-21T11:00:40","date_gmt":"2012-02-21T16:00:40","guid":{"rendered":"http:\/\/wpmu.org\/?p=72368"},"modified":"2022-04-07T01:50:17","modified_gmt":"2022-04-07T01:50:17","slug":"easily-apply-templates-to-your-wordpress-category-pages","status":"publish","type":"post","link":"https:\/\/wpmudev.com\/blog\/easily-apply-templates-to-your-wordpress-category-pages\/","title":{"rendered":"Easily Apply Templates to Your WordPress Category Pages"},"content":{"rendered":"<p>You may know that you can create templates for your category pages in order to make them unique. For example, if you have a category titled \u201cMusic,\u201d you can make a template for that category (category-music.php) that you can then style differently.<\/p>\n<p>But what if you had five categories that you wanted to look one way, five other categories you wanted to look another, and then five more you wanted to look yet another. Even though you only had three different designs, you would need to make fifteen separate category templates, one for each category.<\/p>\n<p>Continue reading, or jump ahead using these links:<\/p>\n<ul>\n<li><a href=\"#simpler-solution\">A Simpler Solution<\/a><\/li>\n<li><a href=\"#how-to-make-a-category-template\">How to Make a Category Template in 4 Steps<\/a>\n<ul>\n<li><a href=\"#step-1\">Step 1: Copy Your Category.php File<\/a><\/li>\n<li><a href=\"#step-2\">Step 2: Create a New Category Template File<\/a><\/li>\n<li><a href=\"#step-3\">Step 3: Paste Contents from Original Category File<\/a><\/li>\n<li><a href=\"#step-4\">Step 4: Edit Your New Category Template<\/a><\/li>\n<\/ul>\n<\/li>\n<li><a href=\"#the-category-template-plugin\">The Category Template Plugin in Action<\/a><\/li>\n<\/ul>\n<h2 id=\"simpler-solution\"><strong>A Simpler Solution<\/strong><\/h2>\n<p>Luckily, there\u2019s a simpler solution \u2013 a plugin called <a href=\"http:\/\/wordpress.org\/extend\/plugins\/custom-category-templates\/\" target=\"_blank\">Custom Category Templates<\/a> that lets you create multiple category templates that you can apply over and over again as you would a Page template.<\/p>\n<p>So in our example above, instead of making fifteen different templates, you would only need to make three, and then apply the correct template to the correct categories.<\/p>\n<p><em>Note:<\/em> Although WordPress.org states that this plugin is outdated, we tested it recently [March 2022] and it worked fine.<\/p>\n<h2 id=\"how-to-make-a-category-template\"><strong>How to Make a Category Template in 4 Steps<\/strong><\/h2>\n<p>The plugin itself is very simple; however, some may not know how to make a category template, and so we\u2019ll go over that first. If you already know how to make a category template, you can skip to the bottom to see the plugin in action.<\/p>\n<p>You will need to create these category templates on your server.<\/p>\n<h3 id=\"step-1\"><span style=\"text-decoration: underline;\"><strong>Step 1: Copy Your Category.php File<\/strong><\/span><\/h3>\n<p>In the folder of your theme (wp-content\/themes\/theme-name) find the file titled <code>category.php<\/code>. (Note: some themes don&#8217;t seem to include this file, so make sure that your does.).<\/p>\n<p>Open it and copy the contents, so you can use that as a starting point for your new category template.<\/p>\n<p><a><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-72371\" title=\"category-file\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/02\/category-file.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"634\" height=\"270\" \/><\/a><\/p>\n<h3 id=\"step-2\"><span style=\"text-decoration: underline;\"><strong>Step 2: Create a New Category Template File <\/strong><\/span><\/h3>\n<p>Create a new category template file and name it something descriptive. It MUST start with the word \u201ccategory\u201d and then a hyphen (\u201ccategory-\u201c). Also, it MUST end with a \u201c.php\u201d \u00a0file extension.<\/p>\n<p>In my example, I am going to put a <a href=\"https:\/\/wpmudev.com\/blog\/wordpress-banner-plugin\/\" target=\"_blank\">banner<\/a> in my template to make it different from the other categories, and so I\u2019m going to name this category template \u201ccategory-banner.php.\u201d<\/p>\n<p>(<strong>NOTE<\/strong>: Make sure you don\u2019t name the file the same as a category on your site.)<\/p>\n<p><a rel=\"lightbox[72368]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/easily-apply-templates-to-your-wordpress-category-pages\/create-new-category-template\/\" rel=\"attachment wp-att-72372\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-72372\" title=\"create-new-category-template\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/02\/create-new-category-template.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"634\" height=\"360\" \/><\/a><\/p>\n<h3 id=\"step-3\"><span style=\"text-decoration: underline;\"><strong>Step 3: Paste Contents from Original Category File <\/strong><\/span><\/h3>\n<p>Now, open the new file you\u2019ve just created (category-banner.php) and paste the contents from your original category.php file into it.<\/p>\n<p>Then, at the <strong>VERY TOP<\/strong> of that file,<strong> BEFORE EVERYTHING ELSE<\/strong>, put the following code with an appropriate name for your template. (In my case, I\u2019m going to name this template \u201cBanner.\u201d)<\/p>\n<pre>&lt;?php\r\n\/*\r\n* Category Template: Banner\r\n*\/\r\n?&gt;<\/pre>\n<p>Your file should look something like this.<\/p>\n<p><a><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-72374\" title=\"name-your-file\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/02\/name-your-file.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"634\" height=\"529\" \/><\/a><\/p>\n<h3 id=\"step-4\"><span style=\"text-decoration: underline;\"><strong>Step 4: Edit Your New Category Template<\/strong><\/span><\/h3>\n<p>Now you can edit your new category template to make it as you like.<\/p>\n<p>In this example, I am going to add a banner to this template. This means that the banner I put in will show up on every category page that gets assigned this template.<\/p>\n<p>Here\u2019s the banner I am adding to my template.<\/p>\n<p><a rel=\"lightbox[72368]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/easily-apply-templates-to-your-wordpress-category-pages\/category-template-banner\/\" rel=\"attachment wp-att-72375\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-72375\" title=\"category-template-banner\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/02\/category-template-banner.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"496\" height=\"87\" \/><\/a><\/p>\n<h2 id=\"the-category-template-plugin\"><strong>The Category Template Plugin in Action<\/strong><\/h2>\n<p>Now that we have the plugin activated, and we\u2019ve made a new category template, we will see options to choose the category templates 1.) when we create a new category, and 2.) when we edit existing categories.<\/p>\n<p><span style=\"text-decoration: underline;\">Creating a New Category<\/span><\/p>\n<p>The option to choose a template for your category appears at the bottom of the left-hand side when you create a new category. (Posts &gt; Categories)<\/p>\n<p><a rel=\"lightbox[72368]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/easily-apply-templates-to-your-wordpress-category-pages\/creating-a-new-category-page\/\" rel=\"attachment wp-att-72376\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-72376\" title=\"creating-a-new-category-page\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/02\/creating-a-new-category-page.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"636\" height=\"858\" \/><\/a><\/p>\n<p><span style=\"text-decoration: underline;\">Editing Existing Categories<\/span><\/p>\n<p>The option to choose a template also appears at the bottom of the page when you are editing an existing category.<\/p>\n<p><a rel=\"lightbox[72368]\" class=\"blog-thumbnail\" href=\"https:\/\/wpmudev.com\/blog\/easily-apply-templates-to-your-wordpress-category-pages\/editing-a-category-page\/\" rel=\"attachment wp-att-72377\" target=\"_blank\"><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-72377\" title=\"editing-a-category-page\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/02\/editing-a-category-page.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"636\" height=\"858\" \/><\/a><\/p>\n<h2><strong>The Result<\/strong><\/h2>\n<p>And here\u2019s the result of my banner template test.<\/p>\n<p><a><img loading=\"lazy\" decoding=\"async\" class=\"aligncenter size-full wp-image-72378\" title=\"banner-template-test\" src=\"https:\/\/wpmudev.com\/blog\/wp-content\/uploads\/2012\/02\/banner-template-test.jpg\" alt=\"Post image\" aria-hidden=\"true\" width=\"637\" height=\"549\" \/><\/a><\/p>\n<p><em>NOTE:<\/em> These templates style only your category pages \u2013 e.g. mysite.com\/category\/music. They do not style the individual posts in the categories. To style custom taxonomies, try the <a href=\"https:\/\/wordpress.org\/plugins\/custom-taxonomy-templates\/\" rel=\"noopener\" target=\"_blank\">Custom Taxonomy Templates plugin<\/a> from the same plugin developer.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Just as you apply templates to Pages, you can now apply templates to category archives.<\/p>\n","protected":false},"author":84404,"featured_media":205569,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"blog_reading_time":"","wds_primary_category":0,"wds_primary_tutorials_categories":0,"footnotes":""},"categories":[4],"tags":[152],"tutorials_categories":[],"class_list":["post-72368","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-plugins","tag-categories"],"_links":{"self":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/72368","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/users\/84404"}],"replies":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/comments?post=72368"}],"version-history":[{"count":10,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/72368\/revisions"}],"predecessor-version":[{"id":208680,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/posts\/72368\/revisions\/208680"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media\/205569"}],"wp:attachment":[{"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/media?parent=72368"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/categories?post=72368"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tags?post=72368"},{"taxonomy":"tutorials_categories","embeddable":true,"href":"https:\/\/wpmudev.com\/blog\/wp-json\/wp\/v2\/tutorials_categories?post=72368"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}