我正在建立一个自定义的Wordpress主题。我在/wp-content/themes/my-theme/wp-includes/post.php中添加了一些自定义帖子类型, 如下所示
// 1. when registering a custom post type set show_in_menu to false, function register_project_custom_type() {
$labels = array(
'name' => _x( 'Projects', 'post type general name', 'your-plugin-textdomain' ), 'singular_name' => _x( 'Project', 'post type singular name', 'your-plugin-textdomain' ), 'menu_name' => _x( 'Projects', 'admin menu', 'your-plugin-textdomain' ), 'name_admin_bar' => _x( 'Project', 'add new on admin bar', 'your-plugin-textdomain' ), 'add_new' => _x( 'Add New', 'project', 'your-plugin-textdomain' ), 'add_new_item' => __( 'Add New Project', 'your-plugin-textdomain' ), 'new_item' => __( 'New Project', 'your-plugin-textdomain' ), 'edit_item' => __( 'Edit Project', 'your-plugin-textdomain' ), 'view_item' => __( 'View Project', 'your-plugin-textdomain' ), 'all_items' => __( 'All Projects', 'your-plugin-textdomain' ), 'search_items' => __( 'Search Projects', 'your-plugin-textdomain' ), 'parent_item_colon' => __( 'Parent Projects:', 'your-plugin-textdomain' ), 'not_found' => __( 'No projects found.', 'your-plugin-textdomain' ), 'not_found_in_trash' => __( 'No projects found in Trash.', 'your-plugin-textdomain' )
);
$args = array(
'labels' => $labels, 'public' => true, 'publicly_queryable' => true, 'show_ui' => true, 'show_in_menu' => true, 'query_var' => true, 'rewrite' => array( 'slug' => 'project' ), 'capability_type' => 'post', 'has_archive' => true, 'hierarchical' => false, 'menu_position' => null, 'menu_icon' => 'dashicons-nametag', 'supports' => array( 'title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments' )
);
register_post_type( 'project', $args );
}
add_action( 'init', 'register_project_custom_type' );
当我进入网址http:// localhost / my-project / project / uma-thurman /时, 它会退回到我的index.php而不是我的single.php。我已经尝试过single.php, archive.php和single-project.php。似乎没有任何作用。
我更新了我的永久链接, 并基于Wordpress应该自动处理这种事情的层次结构进行了思考。
#1
因此, 对于陷入此问题的其他人, 我不得不切换到另一个主题, 然后再切换回去。由于某种原因, 直到执行此操作后, 才能完全识别自定义帖子类型。
评论前必须登录!
注册