[英]Single view of Custom Post Type shows home page
我创建了一个简单的帖子类型lessons
$labels = array(
'name' => _x( 'Lessons', 'Post Type General Name', 'open-college' ),
'singular_name' => _x( 'Lesson', 'Post Type Singular Name', 'open-college' ),
'menu_name' => __( 'Lessons', 'open-college' ),
'parent_item_colon' => __( 'Parent Lesson:', 'open-college' ),
'all_items' => __( 'All Lessons', 'open-college' ),
'view_item' => __( 'View Lesson', 'open-college' ),
'add_new_item' => __( 'Add New Lesson', 'open-college' ),
'add_new' => __( 'Add New', 'open-college' ),
'edit_item' => __( 'Edit Lesson', 'open-college' ),
'update_item' => __( 'Update Lesson', 'open-college' ),
'search_items' => __( 'Search Lesson', 'open-college' ),
'not_found' => __( 'Not found', 'open-college' ),
'not_found_in_trash' => __( 'Not found in Trash', 'open-college' ),
);
$args = array(
'label' => __( 'lesson', 'open-college' ),
'description' => __( 'An Open College lesson', 'open-college' ),
'labels' => $labels,
'supports' => array( 'title', 'editor', 'author', 'comments', ),
'taxonomies' => array( 'category' ),
'hierarchical' => false,
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'show_in_nav_menus' => true,
'show_in_admin_bar' => true,
'menu_position' => 5,
'menu_icon' => '',
'can_export' => true,
'has_archive' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'capability_type' => 'page',
);
register_post_type( 'lesson', $args );
我遇到的问题是,当我创建一个名为“我的示例课”的新课程时,它说我可以在/lesson/my-example-lesson/
查看它,但是当我导航到该URL时,我只会看到主页...
我尝试更新永久链接,甚至删除了mod_rewrite并使用?lesson=my-example-lesson
,但仍然只显示主页。
single.php
甚至没有被调用,它使用的是索引文件。
糟糕! 我发现了问题! 我将钩子分为前端和后端,我只是在后端注册自定义类型,因此当我从前端运行时,WordPress找不到自定义帖子类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.