【发布时间】:2014-02-23 21:16:42
【问题描述】:
我正在尝试在自定义帖子类型中使用自定义页面模板。但是,在尝试添加新页面时,模板选项不会显示在帖子类型中。请看下面的代码:
自定义帖子类型的functions.php:
add_action( 'init', 'register_cpt_product' );
function register_cpt_product() {
$labels = array(
'name' => _x( 'Products', 'product' ),
'singular_name' => _x( 'Product', 'product' ),
'add_new' => _x( 'Add New', 'product' ),
'add_new_item' => _x( 'Add New Product', 'product' ),
'edit_item' => _x( 'Edit Product', 'product' ),
'new_item' => _x( 'New Product', 'product' ),
'view_item' => _x( 'View Product', 'product' ),
'search_items' => _x( 'Search Products', 'product' ),
'not_found' => _x( 'No products found', 'product' ),
'not_found_in_trash' => _x( 'No products found in Trash', 'product' ),
'parent_item_colon' => _x( 'Parent Product:', 'product' ),
'menu_name' => _x( 'Products', 'product' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'description' => 'Product pages',
'supports' => array( 'title', 'editor', 'excerpt', 'thumbnail', 'custom-fields', 'revisions', 'page-attributes' ),
'taxonomies' => array( 'category' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_position' => 5,
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => false,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'page'
);
register_post_type( 'product', $args );
}
页面模板(模板标签除外)
<?php
/*
Template Name: Product
*/
?>
【问题讨论】:
-
你想达到什么目的?您的模板的文件名是什么?
-
模板是single-product.php。我只是尝试将此模板与自定义页面类型一起使用。