所以我使用以下代码为我的wordpress网站制作了一个自定义帖子类型:
add_action( 'init', 'register_cpt_bingo' );
function register_cpt_bingo() {
$labels = array(
'name' => _x( 'Bingo Sites', 'bingo' ),
'singular_name' => _x( 'Bingo', 'bingo' ),
'add_new' => _x( 'Add New', 'bingo' ),
'add_new_item' => _x( 'Add New Bingo Site', 'bingo' ),
'edit_item' => _x( 'Edit Bingo', 'bingo' ),
'new_item' => _x( 'New Bingo', 'bingo' ),
'view_item' => _x( 'View Bingo Site', 'bingo' ),
'search_items' => _x( 'Search Bingo Sites', 'bingo' ),
'not_found' => _x( 'No bingo sites found', 'bingo' ),
'not_found_in_trash' => _x( 'No bingo sites found in Trash', 'bingo' ),
'parent_item_colon' => _x( 'Parent Bingo:', 'bingo' ),
'menu_name' => _x( 'Bingo Sites', 'bingo' ),
);
$args = array(
'labels' => $labels,
'hierarchical' => true,
'supports' => array( 'title', 'editor', 'excerpt', 'author', 'thumbnail', 'trackbacks', 'custom-fields', 'comments', 'revisions', 'page-attributes' ),
'public' => true,
'show_ui' => true,
'show_in_menu' => true,
'menu_icon' => '/wp-content/themes/gamblingq/img/bingo.png',
'show_in_nav_menus' => true,
'publicly_queryable' => true,
'exclude_from_search' => false,
'has_archive' => true,
'query_var' => true,
'can_export' => true,
'rewrite' => true,
'capability_type' => 'page'
);
register_post_type( 'bingo', $args );
}
完美无缺。这是我的管理员面板中的一个屏幕:
如何添加选项以选择自定义页面模板,如下图所示:
任何建议都有帮助!谢谢!