我从youtuber复制了这段代码。这对他有效,但对我无效。代码是否包含任何错误?我一把它放进去,我的WordPress就坏了,无法加载。
function gt_custom_post_type() {
register_post_type(\'project\',
array(
\'rewrite\' => array(\'slug\' => \'projects\'),
\'labels\' => array(
\'name\' => \'Projects\'
\'singular_name\' => \'Project\',
\'add_new_item\' => \'Add New Project\',
\'edit_item\' => \'Edit Project\'
),
\'menu-icon\' => \'dashicons-media-document\',
\'public\' => true,
\'has_archive\' => true,
\'supports\' => array(
\'title\', \'thumnail\', \'editor\', \'excerpt\', \'comments\'
)
)
);
}
add_action(\'init\', \'gt_custom_post_type\');
最合适的回答,由SO网友:Krzysiek Dróżdż 整理而成
这段代码有许多小问题(请参阅下面的注释):
function gt_custom_post_type() {
register_post_type(\'project\',
array(
\'rewrite\' => array(\'slug\' => \'projects\'),
\'labels\' => array(
\'name\' => \'Projects\', // <- missing comma
\'singular_name\' => \'Project\',
\'add_new_item\' => \'Add New Project\',
\'edit_item\' => \'Edit Project\'
),
\'menu-icon\' => \'dashicons-media-document\',
\'public\' => true,
\'has_archive\' => true,
\'supports\' => array(
\'title\', \'thumbnail\', \'editor\', \'excerpt\', \'comments\' // <- thumbnail not thumnail
)
)
);
}
add_action(\'init\', \'gt_custom_post_type\');
而且你还缺乏国际化。。。