自定义帖子类型wordpress

时间:2010-11-29 20:44:35

标签: wordpress wordpress-theming

我想创建一个名为testimonials的自定义帖子类型,为此我想让管理员有机会添加公司名称/用户名以及他们给出的推荐信,我明白我可以通过声明自定义来做到这一点在我的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);
}

2 个答案:

答案 0 :(得分:0)

对于初学者来说,你拼错了重写错误。

答案 1 :(得分:0)

你在功能上缺少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' );

这是一个很好的guide

相关问题