Category

To define a custom template (archive-my-category.html) for a given category (slug my-category):

//In your WP-AppKit theme's functions.js
App.filter( 'template', function( template, current_screen ) {
	if ( TemplateTags.isCategory( 'my-category', current_screen ) ) {
		template = 'archive-my-category'; //Don't need .html here.
	}
	return template;
} );

Custom Post Type

To define a custom single template (single-my-post-type.html) for a given post type (post type’s slug: my-post-type):

App.filter( 'template', function( template, current_screen ) {
	//Check the screen's post type with "TemplateTags.isPostType()" : 
	//as we have to pass the current_screen as 3rd argument, we pass an empty post_id=0 as 2nd argument
	//( because we don't have to check a specific post ID here, just the post type 'my-post-type' ):
	if ( TemplateTags.isPostType( 'my-post-type', 0, current_screen ) ) {
		template = 'single-my-post-type'; //Don't need .html here.
	}
	return template;
} );

And to define a custom archive template (archive-my-post-type.html) for the same post type (my-post-type):

App.filter( 'template', function( template, current_screen ) {
	if ( current_screen.screen_type === 'list' ) {
		if ( current_screen.data.query.post_type === 'my-post-type' ) {
			template = 'archive-my-post-type';
		}
	}
	return template;
} );

Component

To define a custom template (my-template.html) for a given component (component’s slug = “my-component-slug”)

App.filter( 'template', function( template, current_screen ) {
	if ( current_screen.component_id === 'my-component-slug' ) {
		template = 'my-template';
	}
	return template;
} );

To Know More

Here is the doc about:

Published by Mathieu on January 5, 2017

Freelance Senior Web Developer, WordPress since 2009, JS/Backbone since 2012, Custom Back-End devs, WebApps and Plugins for clients and the community.

2 Comments

  1. How to add category title in single.html page?

    Reply

Leave a Reply to Mathieu Cancel reply

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

Having questions?

FAQ | Tutorials | Documentation

Or

Contact Us