Last active
October 14, 2015 19:45
-
-
Save uncatcrea/3f50e35bab5fee013ec2 to your computer and use it in GitHub Desktop.
Shows how to use the 'template' filter to use a custom template for a given app screen
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
Use a custom 'archive-my-category.html' template only for the | |
'my-category' category post list : | |
*/ | |
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; | |
} ); | |
/** | |
Use a custom 'my-component-template.html' template only for the | |
'my-component-slug' component : | |
*/ | |
App.filter( 'template', function( template, current_screen ) { | |
if ( current_screen.component_id == 'my-component-slug' ) { | |
template = 'my-component-template'; //Don't need .html here. | |
} | |
return template; | |
} ); | |
/** | |
Use a custom 'single-my-post-type.html' template only for | |
posts that have the 'my-post-type' post type. | |
*/ | |
App.filter( 'template', function( template, current_screen ) { | |
//Check the screen's post type with "TemplateTags.isPostType()". | |
//Note : 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; | |
} ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment