自定义帖子类型未应用正确的单个帖子模板

时间:2019-01-26 12:57:21

标签: php wordpress

我设置了几种不同的文章类型,每种文章应具有不同的页面布局。按照Wordpress Codex上的说明,我通过复制single.php并将其命名为single-hotel-package.php来创建单个帖子模板,用于下面发布的帖子类型。

/**
 * Register Custom Post Type for Hotel packages
 */
function hotel_packages_post_type() {

    $labels = array(
        'name'                  => _x( 'Hotel packages', 'Post Type General Name', 'resort-hotels' ),
        'singular_name'         => _x( 'Hotel package', 'Post Type Singular Name', 'resort-hotels' ),
        'menu_name'             => __( 'Hotel packages', 'resort-hotels' ),
        'name_admin_bar'        => __( 'Hotel packages', 'resort-hotels' ),
        'archives'              => __( 'Package archives', 'resort-hotels' ),
        'attributes'            => __( 'Package attributes', 'resort-hotels' ),
        'parent_item_colon'     => __( 'Parent Item:', 'resort-hotels' ),
        'all_items'             => __( 'All packages', 'resort-hotels' ),
        'add_new_item'          => __( 'Add new package', 'resort-hotels' ),
        'add_new'               => __( 'Add new package', 'resort-hotels' ),
        'new_item'              => __( 'New package', 'resort-hotels' ),
        'edit_item'             => __( 'Edit package', 'resort-hotels' ),
        'update_item'           => __( 'Update package', 'resort-hotels' ),
        'view_item'             => __( 'View package', 'resort-hotels' ),
        'view_items'            => __( 'View packages', 'resort-hotels' ),
        'search_items'          => __( 'Search package', 'resort-hotels' ),
        'not_found'             => __( 'Package not found', 'resort-hotels' ),
        'not_found_in_trash'    => __( 'Package not found in Trash', 'resort-hotels' ),
        'featured_image'        => __( 'Featured Image', 'resort-hotels' ),
        'set_featured_image'    => __( 'Set featured image', 'resort-hotels' ),
        'remove_featured_image' => __( 'Remove featured image', 'resort-hotels' ),
        'use_featured_image'    => __( 'Use as featured image', 'resort-hotels' ),
        'insert_into_item'      => __( 'Insert into item', 'resort-hotels' ),
        'uploaded_to_this_item' => __( 'Uploaded to this item', 'resort-hotels' ),
        'items_list'            => __( 'Packages list', 'resort-hotels' ),
        'items_list_navigation' => __( 'Packages list navigation', 'resort-hotels' ),
        'filter_items_list'     => __( 'Filter packages list', 'resort-hotels' ),
    );
    $args = array(
        'label'                 => __( 'Hotel packages', 'resort-hotels' ),
        'description'           => __( 'Our selection of hotel packages', 'resort-hotels' ),
        'labels'                => $labels,
        'supports'              => array( 'title', 'editor', 'thumbnail' ),
        'taxonomies'            => array( 'category', 'post_tag' ),
        'hierarchical'          => false,
        'public'                => true,
        'show_ui'               => true,
        'show_in_menu'          => true,
        'show_in_rest'          => true,
        'menu_position'         => 5,
        'menu_icon'             => 'dashicons-admin-post',
        '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( 'hotel-package', $args );

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

但是,这似乎不起作用。我尝试通过保存永久链接页面刷新刷新设置。但是我不认为这是问题所在,因为页面确实显示了内容,而不是我创建的页面模板中的内容。

该页面显示了singlesingle-hotel-package的正文类,只是为了看看会发生什么,我对single.php和page.php进行了一些改动(请确保)。奇怪的是,它什么也没做。获得结果的唯一方法是更改​​content.php。我在这里想念什么?

0 个答案:

没有答案