使用两种自定义帖子类型时,不会显示第二种帖子类型的单个帖子

时间:2016-02-28 23:35:53

标签: php wordpress custom-post-type

我在functions.php中创建了两个自定义帖子类型。一个被称为“商店”,我有single-store.php这个帖子类型,另一个被称为“中心”,我也有single-centre.php这个帖子类型。 single-store.php显示正常,single.php也可以,但single-centre.php根本不会显示。它显示的全部是404错误页面。出了什么问题?

这些是用于注册自定义帖子类型的functions.php中的代码。

// Register Custom Post Type
function stores_post_type() {

    $labels = array(
        'name'                  => _x( 'Stores', 'Post Type General Name', 'text_domain' ),
        'singular_name'         => _x( 'Store', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'             => __( 'Store', 'text_domain' ),
        'name_admin_bar'        => __( 'Post Type', 'text_domain' ),
        'archives'              => __( 'Item Archives', 'text_domain' ),
        'parent_item_colon'     => __( 'Parent Store:', 'text_domain' ),
        'all_items'             => __( 'All Stores', 'text_domain' ),
        'add_new_item'          => __( 'Add New Store', 'text_domain' ),
        'add_new'               => __( 'Add New Store', 'text_domain' ),
        'new_item'              => __( 'New Item', 'text_domain' ),
        'edit_item'             => __( 'Edit Store', 'text_domain' ),
        'update_item'           => __( 'Update Store', 'text_domain' ),
        'view_item'             => __( 'View Store', 'text_domain' ),
        'search_items'          => __( 'Search stores', 'text_domain' ),
        'not_found'             => __( 'No stores found', 'text_domain' ),
        'not_found_in_trash'    => __( 'Not stores found in Trash', 'text_domain' ),
        'featured_image'        => __( 'Featured Image', 'text_domain' ),
        'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
        'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
        'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
        'insert_into_item'      => __( 'Insert into item', 'text_domain' ),
        'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
        'items_list'            => __( 'Items list', 'text_domain' ),
        'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
        'filter_items_list'     => __( 'Filter items list', 'text_domain' ),
    );
    $args = array(
        'label'                 => __( 'Store', 'text_domain' ),
        'description'           => __( 'store information pages', 'text_domain' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'comments', 'custom-fields', ),
        'taxonomies'            => array( 'category', 'post_tag' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 5,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,        
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page',
    );
    register_post_type( 'store', $args );

}
add_action( 'init', 'stores_post_type', 0 );

// Register Custom Post Type
function centres_post_type() {

    $labels = array(
        'name'                  => _x( 'Centres', 'Post Type General Name', 'text_domain' ),
        'singular_name'         => _x( 'Centre', 'Post Type Singular Name', 'text_domain' ),
        'menu_name'             => __( 'Centre', 'text_domain' ),
        'name_admin_bar'        => __( 'Post Type', 'text_domain' ),
        'archives'              => __( 'Item Archives', 'text_domain' ),
        'parent_item_colon'     => __( 'Parent Centre:', 'text_domain' ),
        'all_items'             => __( 'All Centres', 'text_domain' ),
        'add_new_item'          => __( 'Add New Centre', 'text_domain' ),
        'add_new'               => __( 'Add New Centre', 'text_domain' ),
        'new_item'              => __( 'New Centre', 'text_domain' ),
        'edit_item'             => __( 'Edit Centre', 'text_domain' ),
        'update_item'           => __( 'Update Centre', 'text_domain' ),
        'view_item'             => __( 'View Centre', 'text_domain' ),
        'search_items'          => __( 'Search centres', 'text_domain' ),
        'not_found'             => __( 'Not found', 'text_domain' ),
        'not_found_in_trash'    => __( 'Not found in Trash', 'text_domain' ),
        'featured_image'        => __( 'Featured Image', 'text_domain' ),
        'set_featured_image'    => __( 'Set featured image', 'text_domain' ),
        'remove_featured_image' => __( 'Remove featured image', 'text_domain' ),
        'use_featured_image'    => __( 'Use as featured image', 'text_domain' ),
        'insert_into_item'      => __( 'Insert into item', 'text_domain' ),
        'uploaded_to_this_item' => __( 'Uploaded to this item', 'text_domain' ),
        'items_list'            => __( 'Items list', 'text_domain' ),
        'items_list_navigation' => __( 'Items list navigation', 'text_domain' ),
        'filter_items_list'     => __( 'Filter items list', 'text_domain' ),
    );
    $args = array(
        'label'                 => __( 'Centre', 'text_domain' ),
        'description'           => __( 'centre information', 'text_domain' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'custom-fields', ),
        'taxonomies'            => array( 'category', 'post_tag' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'menu_position'         => 6,
        'show_in_admin_bar'     => true,
        'show_in_nav_menus'     => true,
        'can_export'            => true,
        'has_archive'           => true,        
        'exclude_from_search'   => false,
        'publicly_queryable'    => true,
        'capability_type'       => 'page',
    );
    register_post_type( 'centre', $args );

}
add_action( 'init', 'centres_post_type', 0 );

0 个答案:

没有答案
相关问题