WordPress 3自定义帖子类型:如何获得评论

问题描述 投票:2回答:1

我使用4种自定义帖子类型,每种类型都有这种声明:

register_post_type( 'texts', array(
    'labels'=>array('name'=>'Texts','singular_name'=>'Text'),
    'public'=>true,
    'has_archive'=>true,
    'menu_position'=>5
) );

我遇到的问题是这些页面中的帖子没有获得评论链接,说评论已关闭。

有一个名为Texts的页面带有一个/ texts /,它有一个用于博客文章的自定义模板,但它确实启用了注释。

我怎样才能获得评论呢?

wordpress comments custom-post-type
1个回答
4
投票

请参阅http://codex.wordpress.org/Function_Reference/register_post_type中的'supports'参数

或者:http://codex.wordpress.org/Function_Reference/add_post_type_support例如:add_post_type_support('texts','comments');

我的示例代码,从我的主题的functions.php中复制:

// uses sd_register_post_type, which is from http://somadesign.ca/projects/smarter-custom-post-types/, not necessary anymore with WP3.1

add_action( 'init', 'create_post_types', 0 ); // before sd_register_post_type's actions
function create_post_types(){
   $post_supports = array(
     'title'
    ,'editor'
    ,'author'
    ,'thumbnail'
    ,'excerpt'
    ,'trackbacks'
    ,'custom-fields'
    ,'comments'
    ,'revisions'
  );

  $post_type_slug = 'my-news'; // max 20 chars!
  $post_type_slug_plural = $post_type_slug;
  sd_register_post_type( $post_type_slug, array(
    'labels' => array(
               'name' => 'My News',
      'singular_name' => 'My New' // :)
    )
   ,'rewrite' => array(
     'slug' => $post_type_slug
    ,'with_front' => false // don't prepend /blog/...
   )
   ,'public' => true
   ,'hierarchical' => false
   ,'supports' => $post_supports
   ,'menu_position' => 6
   ,'capability_type' => 'post'
  ),$post_type_slug_plural);
}

add_action( 'init', 'register_taxonomies_for_custom_post_types', 11 ); // 11=after sd_register_post_type's actions
function register_taxonomies_for_custom_post_types(){
  $post_type_slug = 'my-news'; // max 20 chars!
  register_taxonomy_for_object_type('category', $post_type_slug);
  register_taxonomy_for_object_type('post_tag', $post_type_slug);
}

add_action( 'init', 'build_taxonomies', 0 );
function build_taxonomies(){
  $post_types = array( 'post', /*'page',*/ 'my-news' );
  register_taxonomy( 'city', $post_types,
    array(
      'public' => true
     ,'labels' => array(
                 'name' => 'Cities',
        'singular_name' => 'City'
      )
     ,'hierarchical' => true
     ,'rewrite' => array(
        'slug' => 'my-news/cities'
       ,'with_front' => false // don't prepend /blog/...
      )
    )
  );
}
© www.soinside.com 2019 - 2024. All rights reserved.