Category Archive Template in Kadence Child Theme

Disclosure: This post may contain affiliate links – meaning I get a commission if you decide to make a purchase through my links, at no cost to you.

This tutorial provides the steps to set up a category.php template file that applies to all category archives by using a Kadence child theme for Kadence.

First, let us see how category archives are rendered when Kadence (the parent theme) is active.

As per the WordPress template hierarchy, since there is no category.php present in Kadence theme, WordPress will look for archive.php. Since this file is not present as well, WordPress will begin with index.php in this case.

index.php:

<?php
/**
 * The main archive template file
 *
 * @package kadence
 */

namespace Kadence;

get_header();

kadence()->print_styles( 'kadence-content' );
/**
 * Hook for main archive content.
 */
do_action( 'kadence_archive' );

get_footer();

The relevant line is:

do_action( 'kadence_archive' );

inc/template-hooks.php has:

/**
 * Archive Content
 *
 * @see Kadence\archive_markup();
 */
add_action( 'kadence_archive', 'Kadence\archive_markup' );

So archive_markup function hooked to kadence_archive hook location is run for rendering the archives and this function is defined in inc/template-functions/archive-functions.php like so.

/**
 * Archive Content
 */
function archive_markup() {
	get_template_part( 'template-parts/content/archive', get_post_type() );
}

That is how the code in template-parts/content/archive.php the file is used for the display of all archives.

To have our own individual template file that applies to only the category archives, we need to copy this archive.php into our child theme, rename it as category.php and edit it while adding

get_header();

kadence()->print_styles( 'kadence-content' );

from index.php at the top and

get_footer();

from index.php at the bottom.

Basically you need to sandwich the code from the immediate applicable parent template between calls to header and footer from index.php.

So here’s the final code of category.php:

<?php
/**
 * The main archive template file for inner content.
 *
 * @package kadence
 */

namespace Kadence;

get_header();

kadence()->print_styles( 'kadence-content' );

/**
 * Hook for Hero Section
 */
do_action( 'kadence_hero_header' );
?>
<div id="primary" class="content-area category">
	<div class="content-container site-container">
		<main id="main" class="site-main" role="main">
			<?php
			/**
			 * Hook for anything before main content
			 */
			do_action( 'kadence_before_archive_content' );
			if ( kadence()->show_in_content_title() ) {
				get_template_part( 'template-parts/content/archive_header' );
			}
			if ( have_posts() ) {
				?>
				<div id="archive-container" class="<?php echo esc_attr( implode( ' ', get_archive_container_classes() ) ); ?>">
					<?php
					while ( have_posts() ) {
						the_post();

						get_template_part( 'template-parts/content/entry', get_post_type() );
					}
					?>
				</div>
				<?php
				get_template_part( 'template-parts/content/pagination' );
			} else {
				get_template_part( 'template-parts/content/error' );
			}
			/**
			 * Hook for anything after main content
			 */
			do_action( 'kadence_after_archive_content' );
			?>
		</main><!-- #main -->
		<?php
		get_sidebar();
		?>
	</div>
</div><!-- #primary -->

<?php get_footer(); ?>

From here you can further customize the category archives template as needed.

Any template parts that are called using get_template_part function can be copied from the parent theme to the child theme directory while maintaining the directory structure and customized.

For example, if we take this line:

get_template_part( 'template-parts/content/entry', get_post_type() );

out of the box it will be loading /wp-content/themes/kadence/template-parts/content/entry.php.

If you want to use a modified copy of it, copy it to /kadence/app/public/wp-content/themes/kadence_child/template-parts/content/entry.php where kadence_child is the folder name of the Kadence child theme. After this, category.php created in this tutorial and any other file that calls entry.php will use this modified file.


Reference: https://developer.wordpress.org/reference/functions/get_template_part/#comment-357

Similar Posts

  • Kadence Child Theme

    Kadence is a highly customizable theme even for beginners and non-coders thanks to its rich and elaborate settings in the WordPress Customizer. For advanced users that want to make any changes in the theme files though it makes sense to use a child theme as the active theme since it allows for template overriding. The…

  • Related Posts in Kadence

    Kadence theme comes with a built-in Customizer setting for showing similar (related) posts on single posts. Let’s see how it actually works under the hood. /kadence/template-parts/content/single-entry.php has: i.e., if the current page is a singular post and if Customizer > Blog Posts > Single Post Layout > Show Related Posts is enabled, then load template-parts/content/entry_related.php….

  • Kadence Membership Price Increase

    The developer of Kadence recently posted an update about Kadence beta, price changes and their rollout plan in their Facebook group. Here is a summary: Features available in the beta of “Kadence Theme Pro”, a plugin that extends Kadence theme with premium features and addons: Header addons, Kadence elements, WooCommerce addons. Beta can be used…

  • Hooked Elements in Kadence

    One of the features that Kadence Theme Pro adds to Kadence theme is called Hooked Elements which provides an interface to build an element using the WordPress Gutenberg editor and hook it to one of the several locations on your pages so it appears exactly where and when you want. A sample use case of…

  • How to Exclude Certain Tags from Single Post Tags in Kadence

    In the previous tutorial, I showed how Elements feature of Kadence can be used to add an affiliate disclosure automatically above the entry content on all posts that have a specific tag. Let’s say you decide to use the “Affiliate Disclosure” tag for this, it will be shown at the bottom of single posts tagged…

  • Custom Fonts in WordPress

    This tutorial provides the steps to set up and use custom fonts in WordPress. Step 1 Upload your font file (typically in .ttf or .otf format) at Font Squirrel to generate the webfont. Step 2 Extract the generated zip file and upload the .woff and .woff2 files to your child theme directory’s fonts directory. If…

2 Comments

  1. It is nice to see modifying category template in kadence. That option is not available in customization. One problem I see that category meta is displayed for each post. It is like a repetition. I want category meta NOT to display for each post in category pages. How?

Leave a Reply

Your email address will not be published. Required fields are marked *