我有许多自定义帖子类型,我想用我最初创建的模板显示这些类型single-photography.php
在我的主题中。
有没有办法将此模板分配给多个自定义帖子类型?
我知道我可以在single.php
具有基于的条件包含的文件get_post_type()
, 但我想知道是否有更好的方法?
我有许多自定义帖子类型,我想用我最初创建的模板显示这些类型single-photography.php
在我的主题中。
有没有办法将此模板分配给多个自定义帖子类型?
我知道我可以在single.php
具有基于的条件包含的文件get_post_type()
, 但我想知道是否有更好的方法?
您可以筛选template_include
并根据您自己的条件将自定义模板作为返回值传递。
未测试的示例代码:
add_filter( \'template_include\', function( $template )
{
// your custom post types
$my_types = array( \'photography\', \'painting\' );
$post_type = get_post_type();
if ( ! in_array( $post_type, $my_types ) )
return $template;
return get_stylesheet_directory() . \'/single-photography.php\';
});
我已经注册了一个名为“Services”的自定义帖子类型,但当我给这篇帖子提供模板“single Services.php”时,它不接受这个,而是选择了“homepage.php”模板,你能告诉我这个问题吗?它也没有使用“archive services.php”模板,而是使用blog模板(index.php)使现代化代码如下:add_action(\'init\', \'services_register\'); function services_register() { $