我创建了三个插件,它们定义了自定义帖子类型并使用template_include
要包括单帖子版本的模板。
出于某种原因,我构建的最新版本正确地创建了记录,但似乎找不到模板。代码实际上是复制和粘贴的,所以我不知道为什么会这样。唯一的更改是函数名和post类型,以避免冲突。
下面是添加template_include
过滤器:
function include_person_template_function($template_path)
{
if (get_post_type() == \'featured_people\') {
if (is_single()) {
if ($theme_file = locate_template(\'single-featured-person.php\')) {
$template_path = $theme_file;
} else {
$template_path = plugin_dir_path(__FILE__) . \'single-featured-person.php\';
}
}
}
return $template_path;
}
add_filter(\'template_include\', \'include_person_template_function\', 1);
由于管理员工作正常,因此唯一可能出现问题的其他部分是在何处定义了帖子类型:
function create_featured_people()
{
register_post_type(\'featured_people\', array(
\'labels\' => array(
\'name\' => \'Featured People\',
\'singular_name\' => \'Featured Person\',
\'add_new\' => \'Add New\',
\'add_new_item\' => \'Add New Featured Person\',
\'edit\' => \'Edit\',
\'edit_item\' => \'Edit Featured Person\',
\'new_item\' => \'New Featured Person\',
\'view\' => \'View\',
\'view_item\' => \'Featured Person\',
\'search_items\' => \'Search Featured People\',
\'not_found\' => \'No Featured People Found\',
\'not_found_in_trash\' => \'No Featured People Found in Trash\',
\'parent\' => \'Parent Featured Person\'
),
\'public\' => true,
\'menu_position\' => 15,
\'supports\' => array( \'title\', \'editor\', \'thumbnail\' ),
\'taxonomies\' => array( \'\' ),
\'has_archive\' => true
));
}
需要注意的其他几点:
我已经排除了缓存问题其他插件使用不同的函数名和CPT名如果您有任何帮助或见解,我们将不胜感激!!