Our Blog

 Custom Theme Categories

Customization: Diving into Different Custom Theme Categories



Customizing your devices with unique themes has become popular, allowing you to showcase your style and personalize your gadgets. WordPress offers various custom template categories, including complex patterns, bright colors, and minimalist designs. To give your website a unique touch, developers often develop custom category themes. By using code editing, you can layout unique templates using WordPress's adaptability. This can be done by creating your own archive file or changing the appropriate archive files. This article will discuss the benefits of using a custom WordPress categories theme.

Understanding WordPress's Template Hierarchy:

WordPress themes begin with page themes and post section templates, which are searched for using a hierarchical structure. When searching for a template for a category page, WordPress looks left to right, searching for category-id.php and index.php. Most themes have a category.php or archive.php file, which represents the design template for all archived pages and categories. To create a custom theme for a specific category, generate a unique file called category-id.php and category-slug.php, replacing the slug/ID with the appropriate file titles. This requires FTP knowledge to add and modify files on the server.

How to Create a WordPress Custom Categories Templates:

You can make a custom category theme in a few different methods. We will discuss three practical coding methods using the parts that follow. These include creating category-specific personalised CSS code, utilising conditional statements inside a single archive file (category.php and archive.php), and generating custom template files. We will also discuss the benefits and disadvantages of each of these approaches. Additionally, carefully chosen examples of code will be provided for each of the aforementioned methods. It is entirely up to you to enhance the samples we provided; still, they serve as illustrations of a topic.

Additionally, you are able to use numerous methods at once. This primarily relates to generating custom CSS because you will most likely use CSS to style the template that you build in the future. The category content that your custom templates display may not be visually pleasing since it uses the browser's standard styles (or a combination of theme and default browser stylization). Because of this, you might have to style it even more to achieve the precise appearance you intended when you created the template.  That being said, let's move on to the processes for making unique category themes.

  • Creating a Separate Custom Theme:
  • WordPress themes begin with page themes and post section templates, which are searched for using a hierarchical structure. When searching for a template for a category page, WordPress looks left to right, searching for category-id.php and index.php. Most themes have a category.php or archive.php file, which represents the design template for all archived pages and categories. To create a custom theme for a specific category, generate a unique file called category-id.php and category-slug.php, replacing the slug/ID with the appropriate file titles. This requires FTP knowledge to add and modify files on the server.

    Please be mindful that in order for this code to function properly when you copy it, you must remove the underscore character ("_") from each instance of "_substr." Thus, $excerpt = substr and $short_excerpt = substr should be utilised in your source code instead.

    Explanation: A string with a request to retrieve all of the most current four entries in a category with the "fitness" slug is stored in the $category_query variable.

    1. $category_query = new WP_Query( array( 'category_name' => 'fitness', 'posts_per_page' => '4' ) ); 

    There are multiple parts in the starting section. The first section displays a picture named fitness.jpg that was posted over FTP to the parent theme's folder. The category title in addition to the text ": latest posts" are combined to create a title that appears next (as an instance, "Nutrition: latest posts"). Lastly, the category explanation will appear when it is present.

    The main part includes an if...else... expression. There is a while loop with related code inside the conditional clause. One of the more simplistic instances of a WordPress loop can be seen in this entire code section. The WordPress Loop executes the commands that are included in the relevant code blocks and retrieves data from posts in accordance with a specified question. In particular, the relevant post-content block is created with the post's data if it matches the query. If not, the screen displays a statement saying, "Sorry, no responses matched your criteria

    As you can see, it has the following details:

    • Thumbnail for a medium-sized post
    • The title of the blog post that, when clicked, leads to the right post, as well as the first 80 characters of the excerpt.

    Naturally, users can change these values to make your source code unique. When you are utilising several loops, that is, numerous queries that correspond to those loops, then this function is quite beneficial. The global $post variable's value is reset to the value that it was while the main query was executing.

    The final three functions are get_header(), get_footer(), and get_sidebar(). We put them in the final part due to their differences in usage; they behave similarly. They load the sidebar of the footer and header templates in that ratio.

  • Make use of conditional statements:
  • To create multiple templates in WordPress, use conditional expressions in the file categories.php, archive.php, and index.php. Backup the modified theme file before making changes. The is_category function is crucial for determining if a page is classified as an archive page or not. It can apply code to all categories or an array of classes. Combine the is_category utility with your preferred expression. The code is divided into two parts: a conditional statement for posts to fall under the "Fitness" category, and an else clause if criteria are not met.

    • <?php if(is_category( 'Fitness' )):
    • <h1 class="archive-title">Fitness articles</h1>
    • <?php else:?>
    • <h1 class="archive-title"> Everything about <?php single_cat_title();?> </h1>
    • <?php endif;?> 

    We must note that the code below is intended to be used in a post loop before moving on to our second example. Differing post content will appear based on the category. Therefore, the number of comments and the post's publication date will be displayed on the "Fitness" category page. Posts with excerpts will appear on the "Training Programme" category page; for all other categories, only a sizable post thumbnail will be displayed.

    Consequently, the code meant for the "fitness" category is indicated by the first if statement, and the code relating to the "training programme" category is indicated by the otherwise if statement. All of the remaining categories are addressed by the code that is enclosed in the final else expression.

    • <?php
    • if (is_category( 'fitness' ) ) {?>
    • <p>Published on <?php the_date('d M Y', '<span class="post-date">', '</span>');?></p>
    • <span class="comment-number"> <?php comments_number( 'no comments', '1 comment', '% comments' );?></span>
    • <?php } else if (is_category( 'training-programme' ) ) {?>
    • <p><?php echo wp_kses_post( get_the_excerpt());?></p>
    • <?php } else {?>
    • <div><?php the_post_thumbnail( 'large' );?> </div>
    • <?php }?>

    Even though this approach might seem appealing, there may be problems with the code's readability, particularly if the file is excessively large. It will also be challenging to find any mistakes in the code. Use correct syntax, indentation, and useful remarks to help clarify specific code portions in order to help prevent these errors. It is generally advised that you follow these best practices for coding while creating any type of code, as they constitute a few of the most widely accepted standards.

  • Writing Custom Category-Specific CSS
  • Write custom CSS code when you only need to make minor adjustments to your category page. You have two choices: use media queries to be more precise, or write the code to affect all widths and viewports. You must specify a distinct selector, such as the ID for your category, if you wish to apply the code to a certain category. You can ensure that the code applies to only one category of your choice by adding an additional class that corresponds to the ID. Without becoming too technical, we'll give a brief description of this in the section that follows.

    We'll begin with the presumption that you already have some CSS code ready to go and that you would like to utilise it specifically for one category.

    • h1.archive-title {
    • text-align: centre;
    • position: relative;
    • top: -18px;
    • left: 0;
    • colour: white;
    • }

    You need to look at that category page in order to customise this CSS code to be category-specific. You may also choose the Inspect option by clicking right on any element on the website and pressing the F12 key on your computer's keyboard.

    This will launch the Chrome tools for developers and show you the Elements tab, from which you can see the precise HTML element you click on.

    Look for the first tag and the associated classes in the same section; they should be towards the top. It should be fairly easy to see the subclass with the category ID once you locate it.

    Since the class for this instance is category 17, the category ID is also 17. You must prefix the CSS selector shown above with the title of the category (category-17) in order to make the source code unique to that category. Because it is a subclass name, remember to add a dot (.) after it! As a result, the instance of CSS should now seem like this:

    • .category-17 h1.archive-title {
    • text-align: centre;
    • position: relative;
    • top: -18px;
    • left: 0;
    • colour: white;

    The code will become category-specific as a result. Only webpages with the class archive-title and a body class of category-17 are subject to all the rules enclosed in parenthesis.

    Likewise, you may use media queries to package any CSS code and apply it to a given viewport, range width, and selectively. The first line of the code indicates that it is only suitable for shows that have an essential width of 1025 pixels.

    • @media only screen and (min-width: 1025px) {
    • .category-17 div.main-content {
    • width: 65%;
    • margin: 0.5%;
    • display: inline-block;
    • }
    • }

    The next step after creating your personalised CSS code is to arrange it appropriately so that it is applicable, in accordance with the previous instructions. Go to Appearance > Customise on the admin panel after signing in to do this.

    After selecting the Additional CSS option and entering your customised CSS, press the Publish button.

  • Utilising widgets and plugins:
  • There are a few simple ways to make a specific page display blog entries under a single category when you're just starting out and prefer dealing with easier-to-use alternatives.

    More specifically, users may accomplish this by generating beautiful lists of posts that can be customised to show only specific entries, like those that fall under a particular category, using the Blog List widget included in the Qi Addons for Elementor collection. It's quite easy to use: after installing the Qi Addons plugins, you'll have access to over 100 customisable widgets for different uses. Next, all you have to do is add the BLog Listing widget to the page you have chosen and choose Category under "Taxonomy" in the "Query" section.

    Users of Gutenberg need not fret, as there is a nearly identical Gutenberg block available for building a list of blogs. It has the same cutting-edge style and abundance of fully customisable settings. A variety of list styles are easily accessible, including boxed, minimalist, and single with a side image. Therefore, as a template, you can develop rich and interesting pages that truly attract users to click on your material, in addition to just listing the categories on one page.

    What is the hierarchy of WordPress templates:

    Every element of a WordPress website has a template, which varies based on the theme because WordPress is a dynamic website.

    WordPress loads the page in response to each query that is generated. The output that you want can be obtained by executing this query over the template hierarchy.

    Thus, WordPress uses an approach called a template hierarchy to figure out which template files must be installed in what order on your website to show the pages you've chosen.

    WordPress Template Hierarchy Structure:

    Based on the template's file hierarchy, the following figure demonstrates which of the template files are used to create a WordPress page.

    WordPress Template Structure Based on the Type of Page

    The majority of WordPress websites employ one of these eight page types:

    Front page template files:

    Your home page is where customers arrive first. Despite variations in design, all home page layouts adhere to a single general concept. This suggests that the following folders load sequentially when a query string pertaining to the home page is generated:

    • Front-page.php
    • Home.php
    • Index.php

    If front-page.php is missing from your theme, WordPress will open the second file in order, and so on. WordPress returns index.php in the absence of a template file, and this is the last stop for every query within the template hierarchy.

    Single posts:

    Each individual article uses a single post theme hierarchy and is treated as a single post.

    The complexity of the theme hierarchy for individual posts can vary based on the customisation settings you choose. However, the following is the fundamental theme hierarchy for individual posts:

    • Single.php
    • Singular.php
    • Index.php

    Single pages:

    Single-page themes can contain a complex template hierarchy, just like single posts. The following is the fundamental single-page theme hierarchy:

    • Page.php
    • Singular.php
    • Index.php 

    Custom post types:

    You can add a distinctive touch to your brand by using WordPress to build specific types of posts for your website. Custom post kinds, which have their own theme hierarchy and are organised as follows, keep visitors engaged with your business.

    • Archive-{post_type}.php
    • Archive.php
    • Index.php

    Even though the custom post type template hierarchy is straightforward, you can add additional parts to it based on the level of customisation you want to do. Additionally, WordPress themes allow you to make custom page layouts.

    Search result pages:

    The majority of WordPress-powered websites have a search function. The template hierarchy for the search result page is simple. It is shown as follows:

    • Search.php
    • Index.php

    Category and tag pages:

    For tags and categories, WordPress creates communal pages. Numerous components, each with its own template hierarchy, can be found on category and tag pages. For this reason, the categories and tag pages' theme hierarchy can be quite flexible and complex.

    The following is the design of the category page's basic templates:

    • category–{slug}.php
    • category-{id}.php
    • category.php
    • archive.php
    • index.php

    As opposed to this, the tag page's basic templates look like this:

    • tag–{slug}.php
    • tag-{id}.php
    • tag.php
    • archive.php
    • Index.php

    404 error pages:

    WordPress displays a 404 error page for users who attempt to get to a page that is not available. Even if the website does not have many editable elements, you can still alter the design to suit your requirements.

    The template hierarchy for the 404 error page is really easy to understand and looks like this:

    • Index.php 
    • 404.php

    Which WordPress template files are important:

    Almost all page layouts allow users to include certain WordPress files, which are as follows: 

    • Index.php
    • Header.php
    • Footer.php
    • Sidebar.php


    A WordPress theme cannot work without the template file index.php, which is located in the WordPress page hierarchy. It is primarily used to render the home page of a theme. You may choose the most suitable WordPress themes for your online presence by understanding this file.

    Other template files, such as header.php, footer.php, and sidebar.php, that contain the head section, footer subject matter, and sidebars with widget portions of the website, usually reside in the index.php file. A loop that shows the pages and posts on the template is also included.

    WordPress loads index.php when the template file—such as single.php or post.php—is absent.


    The head.php file, which frequently appears at the starting point of all template files, contains the head portion of a WordPress website. Typically, it includes header data, statistics, CSS file calls, site navigation, site titles, the site logo, and others.


    The WordPress theme's footer component is constructed using the footer.php file. All template files have a footer section that calls it. Calls to JavaScript files, copyright data, and widget sections with site navigation typically appear in the file.


    As its name implies, the sidebar.php file is used for building a website's sidebar and typically includes widget regions for simple modification. In template files such as index.php, page.php, and single.php, the sidebar is named. When your design calls for it, you can also take the sidebar off the website.

    The following are some additional template documents that we frequently use but don't need to have:


    WordPress search results are generated using the search.php template code. The search results are generated from index.php if the file is not available.


    Attachment pages, including pictures and videos, are displayed using the attachment.php template file. To produce pictures and movies, use the filenames image.php and video.php accordingly. Additionally, the computer system uses attachment.php when any of these files are missing and cannot be retrieved.


    The error page is produced from the index.php file when the file is missing. The 404.php file displays the file was not found page.


    To add comment functionality, templates such as single.php or page.php call the comments.php file, which is a theme of comments.

    How does the template hierarchy in WordPress operate:

    WordPress chooses the template and collection of templates to use for the page's appearance based on a query string. 

    To put it another way, WordPress looks through the template's hierarchy until it locates a file that matches. This is how it operates: 

    WordPress first receives the query string and user input. It verifies the theme being used by the particular site in question. After that, it checks the query string and query type to ascertain which page is being asked before retrieving the pertinent template hierarchy.

    Verify whether the first template file is available. Display it when it is available; when not, move on to the next file in the order in which they appear. If there is nothing to show, display the index.php file.

    Why WordPress Uses a Template Hierarchy:

    For easy WordPress site modification, we want an outline hierarchy. Additionally, a template hierarchy might be needed for the following uses:

    At any one time, specify to WordPress which of the template files within the theme you want to use.

    You have the advantage of being able to customise your themes to suit your needs. It improves the user's comprehension of the theme.

    It maintains the content management system's order.

    How to Find and Modify the WordPress Template Hierarchy:

    By utilising a Filezilla FTP client to access the programme's root folder, you may quickly find the WordPress template hierarchy. Take the actions mentioned below:

    • Make an account with the FTP client using the Master Credentials.
    • Navigate to Applications, then choose your WordPress app by the name of the database.
    • Go to public-html.
    • Click on wp-content. Select themes
    • Decide on an outline. I'm going to pick twenty-twenty-one here.
    • All of your.php files will be displayed for you to see.
    • Open one of the.php files and perform the modifications that are required.

    WordPress Template Hierarchy's Child Themes:

    Although child themes aren't readily apparent in the cheat sheet, you may still use them in the WordPress theme hierarchy.

    If you are interested in changing the WordPress subject, your best option is to use a child theme. It adds an extra layer to a template's hierarchy for each page type users use and allows you to easily and safely change your themes. In addition, you can personalise your website by using full-site editing themes.


    When you want to create unique themes and alter the WordPress theme file structure, it helps to understand the WordPress template hierarchy. You may quickly locate the appropriate template files to alter and personalise with their assistance. After configuring your WordPress hosting and your servers, you are able to understand how the template hierarchy functions.

    The WordPress theme hierarchy's commitment to a rigid naming system is its best feature. Therefore, after you've comprehended the template structure, creating WordPress themes will be simple for you. For a quick visual reference when developing themes, anyone can consult the WordPress theme hierarchy.



    What is a custom WordPress category theme?

    A custom WordPress category theme is a unique design and layout specifically created for a particular category or group of categories on a WordPress website. It allows you to customize the appearance and functionality of category pages according to your preferences.

    Why would I need a custom category theme?

    Custom category themes help you showcase your style, personalize your website's appearance, and create a more engaging user experience. They allow you to highlight specific content, promotions, or products related to a particular category, improving navigation and user engagement.

    How can I create a custom category theme in WordPress?

    You can create a custom category theme in WordPress by generating unique template files such as category-id.php or category-slug.php, where "id" and "slug" represent the category identifier or slug. These files can be customized using HTML, CSS, PHP, and WordPress template tags to achieve the desired layout and functionality.

    What are the benefits of using custom category themes?

    Custom category themes offer unique designs, enhanced user experience, targeted content presentation, SEO optimization, brand consistency, and visual appeal.

    Can I use plugins or widgets to enhance my custom category themes?

    Yes, you can use plugins or widgets to enhance the functionality of your custom category themes. For example, you can use plugins to add custom post types, display related posts, create interactive elements, or integrate social media features into category pages.