我已将您的CPT代码复制到本地主机。我不得不补充register_post_type( \'facebook\', $args );
让CPT发挥作用。不知道您是否忘记将这段代码添加到问题中的代码中。我还补充道\'has_archive\' => true,
正如我之前所建议的那样。然后,我更新了我的永久链接,该链接设置为“Post name”。
我还创建了两个模板,archive-facebook.php
和single-facebook.php
. 这正如预期的那样。
我在子主题和父主题中对此进行了测试。
其他注意事项,\'add_new_item\' => __("Add new Facebook post"),
本地化是错误的。翻译人员does not 识别内部字符串"
. 您应该始终使用单引号\'
喜欢\'add_new_item\' => __(\'Add new Facebook post\'),
这是您修改过的代码,经过测试,它运行得非常完美
$labels = array(
\'name\' => _x(\'Facebook\', \'post type general name\'),
\'singular_name\' => _x(\'Facebook\', \'post type singular name\'),
\'all_items\' => __( \'All posts\' ),
\'add_new\' => _x(\'Add new post\', \'Facebook\'),
\'add_new_item\' => __(\'Add new Facebook post\'),
\'edit_item\' => __(\'Edit Facebook post\'),
\'new_item\' => __(\'New Facebook post\'),
\'view_item\' => __(\'View Facebook posts\'),
\'search_items\' => __(\'Search in Facebook posts\'),
\'not_found\' => __(\'No facebook posts found\'),
\'not_found_in_trash\' => __(\'No facebook posts found in trash\'),
\'parent_item_colon\' => \'\'
);
//$post_supports = array(\'title\',\'editor\',\'comments\',\'thumbnail\',\'excerpt\');
$post_supports = array(\'title\',\'editor\',\'thumbnail\');
$args = array(
\'labels\' => $labels,
\'public\' => true,
\'publicly_queryable\' => true,
\'show_ui\' => true,
\'query_var\' => true,
//\'menu_icon\' => get_stylesheet_directory_uri() . \'/images/slider.png\',
\'rewrite\' => true,
\'capability_type\' => \'post\',
\'hierarchical\' => false,
\'menu_position\' => null,
\'supports\' => $post_supports,
\'has_archive\' => true
);
register_post_type( \'facebook\', $args );
请阅读与以下内容相关的法典:
custom post types 和
register post type