Here 我读到,如果我创建一个自定义的帖子类型,Wordpress将首先查看它的特定模板,然后返回到single。php。
我注册了一个自定义的post类型(我还将显示分类法),它在admin中正确显示;我可以很好地创建它们,并且可以将它们添加到博客主页的帖子列表中。然而,当我尝试访问它的页面时,并没有收到404错误,但标题并没有显示在标题部分,它使用了索引。php模板,虽然我有一个。php,这是与常见的职位,我想使用。我的新类型(在functions.php中)
function mytheme_customtypes () {
$post_args = array(
\'label\' => _(\'Blog Post\'),
\'description\' => _(\'Site\\\'s blog posts\'),
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'taxonomies\' => array(\'blog_posts\'),
\'supports\' => array(\'title\', \'editor\', \'comments\', \'trackbacks\', \'thumbnail\'),
\'capability_type\' => \'post\',
\'rewrite\' => array(\'slug\' => \'blog\', \'has_archive\' => \'blog_posts\', \'with_front\' => false)
);
$tax_args = array(
\'label\' => \'Blog posts\',
\'description\' => _(\'Raccolta dei post per il blog\'),
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'rewrite\' => array(\'slug\' => \'blogs\', \'with_front\' => false),
\'hierarchical\' => true
);
register_post_type(\'blog_post\', $post_args);
register_taxonomy(\'blog_posts\', \'blog_post\', $tax_args);
}
add_action(\'init\', \'mytheme_customtypes\');
正在尝试创建新模板名称single-blog\\u post。php没有任何效果。非常感谢您的帮助
最合适的回答,由SO网友:Milo 整理而成
public
是false
默认情况下,如果未将帖子类型显式设置为true
.
$post_args = array(
\'public\' => true,
\'label\' => _(\'Blog Post\'),
\'description\' => _(\'Site\\\'s blog posts\'),
\'show_ui\' => true,
\'show_in_nav_menus\' => true,
\'taxonomies\' => array(\'blog_posts\'),
\'supports\' => array(\'title\', \'editor\', \'comments\', \'trackbacks\', \'thumbnail\'),
\'capability_type\' => \'post\',
\'rewrite\' => array(\'slug\' => \'blog\', \'has_archive\' => \'blog_posts\', \'with_front\' => false)
);