自定义帖子类型的单一视图显示主页

时间:2014-02-28 05:21:13

标签: php wordpress custom-post-type

我创建了一个简单的帖子类型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甚至没有被调用,它正在使用索引文件。

1 个答案:

答案 0 :(得分:0)

糟糕!我发现了问题!我的钩子分为前端和后端,我只在后端注册自定义类型,所以当我从前端运行时WordPress没有找到自定义帖子类型。