[英]custom post types wordpress
我想创建一个称为“推荐”的自定义帖子类型,为此,我想让管理员有机会添加公司名称/用户名以及他们提供的推荐信息,我知道我可以通过声明一个自定义帖子类型来做到这一点。在我的functions.php
文件中,但是它似乎不起作用,我得到的只是普通的帖子字段,有人可以告诉我我要去哪里错了,或者我该怎么做?
function testimonials_register() {
$args = array(
'label' => __('Testimonials'),
'singular_label' => __('Testimonial'),
'public' => true,
'show_ui' => true,
'capability_type' => false,
'hierarchical' => false,
'rewirte' => true,
'supports' => array('title', 'editor')
);
register_post_type('testimonial', $args);
}
您缺少add_action('init', 'testimonials_regiser');
功能。
更加个性化的更彻底的代码如下:
function testimonials_register() {
$labels = array(
'name' => _x( 'Testimonials', 'post type general name' ),
'singular_name' => _x( 'Testimonial', 'post type singular name' ),
'add_new' => _x( 'Add New', 'testimonial' ),
'add_new_item' => __( 'Add New Testimonial' ),
'edit_item' => __( 'Edit Testimonial' ),
'new_item' => __( 'New Testimonial' ),
'all_items' => __( 'All Testimonials' ),
'view_item' => __( 'View Testimonial' ),
'search_items' => __( 'Search Testimonials' ),
'not_found' => __( 'No testimonials found' ),
'not_found_in_trash' => __( 'No testimonials found in the Trash' ),
'parent_item_colon' => '',
'menu_name' => 'Testimonial'
);
$args = array(
'labels' => $labels,
'description' => '',
'public' => true,
'menu_position' => 5,
'supports' => array( 'title', 'editor'),
'has_archive' => true,
);
register_post_type( 'testimonial', $args );
}
add_action( 'init', 'testimonials_register' );
这是一个很好的指南 。
对于初学者,您拼写错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.