2013-06-23 90 views
0

註冊信息類型在我的wordpress中不起作用。註冊信息類型不起作用

這裏是所有的代碼。

register_activation_hook(__FILE__, array('Cp_Setup', 'cpActivatePlugin')); 

class Cp_Setup{ 
public static function init(){ 

} 
public function cpActivatePlugin(){ 
    self::_cpCreateCustomPostType(); 
} 
// Registering Custom Post Type if it isn't already registered. 
private function _cpCreateCustomPostType(){ 
    $labels = array(
      'name' => __('Custom Posts'), 
      'singular_name' => __('Custom Post'), 
      /* etc. */ 
      'parent_item_colon' => __('Parent Page (Custom Post)') 
    ); 
    $args = array(
      'labels' => $labels, 
      'public' => true, 
      'menu_position' => 15, 
      'supports' => array('title', 'editor', 'comments', 'thumbnail', 'custom-fields'), 
      'taxonomies' => array(''), 
      'menu_icon' => plugins_url('images/image.png', __FILE__), 
      'has_archive' => false 
    ); 
    register_post_type('cp_custom_post',$args); 
} 
} 

但上述代碼未註冊任何名爲「cp_custom_post」的帖子類型。

+0

'_cpCreateCustomPostType'函數是否運行?你是否在日誌中打印了某些內容以確保其執行? – montrealist

回答

0

_cpCreateCustomPostType()需要在每個請求上運行;不只是當你激活插件。鉤入init鉤子,或者通常使用的鉤子註冊自定義帖子類型。