自定义帖子类型 WordPress

发布于 2024-10-05 05:37:18 字数 535 浏览 1 评论 0原文

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

I am wanting to create a custom post type called testimonials, for this I am wanting to allow the administrator that chance to add a company name/username and what testimonial they have given, I understand I can do this by declaring a custom post-type in my functions.php file, however it does not seem to work and all I get is the normal post fields, can someone tell me where I am going wrong, or how I would do this please?

 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);
}

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

稚然 2024-10-12 05:37:18

首先,您拼写重写错误。

You spelled rewrite wrong, for starters.

哆兒滾 2024-10-12 05:37:18

您在函数之后缺少 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' );

这是一个很好的 指南

You are missing add_action('init', 'testimonials_regiser'); afer the function.

A more thorough code that's a bit more customized can be as follows:

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' );

Here is a good guide.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文