Wordpress不进入自定义帖子类型页面
我正在构建一个自定义Wordpress主题。我在Wordpress不进入自定义帖子类型页面,wordpress,wordpress-theming,custom-wordpress-pages,Wordpress,Wordpress Theming,Custom Wordpress Pages,我正在构建一个自定义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' =&g
/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' );
当我转到urlhttp://localhost/my-project/project/uma-thurman/
对于其中一个,它将返回到我的index.php,而不是我的single.php。我尝试过single.php
,archive.php
和single project.php
。似乎什么都不管用
我更新了我的permalinks,我认为基于Wordpress应该自动处理这样的事情的层次结构。因此,对于其他陷入此问题的人,我必须切换到不同的主题,然后再切换回来。出于某种原因,在执行此操作之前,无法完全识别自定义帖子类型。您缺少大量有助于解决此问题的详细信息。例如,您访问的哪个URL“回退”到index.php模板?第二,您是否已在仪表板中转到永久链接部分并保存?(这是添加新职位类型后所必需的)。你上面贴的代码在哪里?(在哪个文件中-插件?你的主题?如果你的主题,在哪里?)?怎么会?啊。我和Wordpress合作已经有几年了,当你第二次提到保存永久链接时,我想一定是这样。唉,它仍然不起作用。我将永久链接更改回默认值http://localhost/my-project/?project=uma-thurman
但它仍然不起作用。代码肯定在运行。它显示在我的管理面板上,我可以添加自定义字段并填写它们。在wp includes/post.php
BTW中,转到索引页实际上意味着它是一个404-您可以确认这是一个有用的情况…是的,将slug更改为类似project xyzpdq
的内容或其他内容,这样您就可以100%确信没有slug冲突。