2011-03-17 95 views
2

我使用4種自定義文章類型每個都具有這樣的聲明: register_post_type('texts',array('labels'=>array('name'=>'Texts','singular_name'=>'Text'),'public'=>true,'has_archive'=>true,'menu_position'=>5));WordPress的3自定義文章類型:如何獲得評論

我的問題是,在這些網頁的帖子沒有得到評論的鏈接,說評論被關閉。

有一個Page創建了一個叫做Texts的文本,其中包含一個/ texts /,它有一個博客文章的自定義模板,但它確實啓用了註釋。

請問我該如何評價工作?

回答

4

參見這裏的 '載體' 參數, http://codex.wordpress.org/Function_Reference/register_post_type

或: http://codex.wordpress.org/Function_Reference/add_post_type_support 例如: add_post_type_support( '文本', '註釋');

我的示例代碼,從我的主題的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/... 
    ) 
    ) 
); 
} 
+0

你好,謝謝。我在'register_post_type'函數的數組參數中添加了支持,但沒有任何反應。在wp-admin中,我沒有看到「允許評論」複選框,而在公開部分,它只是說'評論已關閉。「。怎麼了? – Francisc 2011-03-17 14:27:25

+1

嗨,評論可以被禁用/啓用每個帖子的基地,在帖子編輯器頁面的底部。它是否啓用了您的測試帖子? ('name'=>'News','singular_name'=>'News') ,'rewrite'=>數組('蛞蝓」 => $ post_type_slug, 'with_front'=>假) , '公共'=>真 , '分層'=>假 '載體'=>數組( '標題' '編輯' , '作者' , '縮略圖' , '摘錄' , '引用通告' , '自定義字段' , '意見' , '修訂' ) ,「menu_posit ion'=> 6 ,'capability_type'=>'post'' – biziclop 2011-03-17 19:41:30

+0

嗨,biziclop。您的評論不適合。 :)你應該把它添加到你的答案,請。 – Francisc 2011-03-18 12:08:16

相關問題