Skip to content

Instantly share code, notes, and snippets.

@destos
Created February 15, 2012 22:51
Show Gist options
  • Select an option

  • Save destos/1839779 to your computer and use it in GitHub Desktop.

Select an option

Save destos/1839779 to your computer and use it in GitHub Desktop.
get_post_type_template
function get_post_type_template( $context = null ) {
$type = (string) get_post_type( get_the_ID() );
$format = (string) get_post_format( get_the_ID() );
do_action( "get_post_type_template_{$type}", $format, $context );
$templates = array();
if ( !empty($format) ){
if(is_array($context)){
foreach($context as $con)
$templates[] = "type-{$type}-{$format}-{$con}.php";
}else{
$templates[] = "type-{$type}-{$format}-{$context}.php";
}
$templates[] = "type-{$type}-{$format}.php";
}
if(is_array($context)){
foreach($context as $con)
$templates[] = "type-{$type}-{$con}.php";
}else{
$templates[] = "type-{$type}-{$context}.php";
}
$templates[] = "type-{$type}.php";
locate_template( $templates, true, false );
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment