2014-02-24 72 views
0

我想知道如何使用WordPress創建自定義帖子類型的過程。如果有人幫我完成代碼和插件的程序,我會很感激。我也將寫關於這個問題的博客文章,我需要來自Stackoverflow的頂級貢獻者的幫助。之後與此類似如何在WordPress中創建自定義帖子類型?

+0

的完整代碼的理解:http://cmsblogheart.wordpress.com/2014/03/07/wordpress-custom-post-type/ –

回答

1

代碼添加到您functions.php

add_action('init', 'create_post_type'); 
function create_post_type() { 
    register_post_type('your_custom_name', 
     array(
      'labels' => array(
       'name' => __('Custom_names'), 
       'singular_name' => __('Custom_names') 
      ), 
     'public' => true, 
     'has_archive' => true, 
     ) 
    ); 
} 

你可以看到在你的左邊dashbooard欄添加自定義職位的另一種選擇。 see more about Post Types

0
function my_custom_event() { 
    $labels = array(
    'name'    => _x('Events', 'post type general name'), 
    'singular_name'  => _x('Events', 'post type singular name'), 
    'add_new'   => _x('Add New', 'Events'), 
    'add_new_item'  => __('Add New Events'), 
    'edit_item'   => __('Edit Events'), 
    'new_item'   => __('New Events'), 
    'all_items'   => __('All Events'), 
    'view_item'   => __('View Events'), 
    'search_items'  => __('Search Events'), 
    'not_found'   => __('No Events found'), 
    'not_found_in_trash' => __('No Events found in the Trash'), 
    'parent_item_colon' => '', 
    'menu_name'   => 'Events' 
); 

$args = array(
    'labels'  => $labels, 
    'description' => 'Events', 
    'public'  => true, 
    'show_ui'  => true, 
    'capability_type' => 'post', 
    'menu_position' => 5, 
    'supports'  => array('title' , 'thumbnail', 'editor', 'page-attributes'), 
    'has_archive' => true, 
); 

register_post_type('event', $args); 
} 
add_action('init', 'my_custom_event'); 
+0

有一點敘述解釋你在這裏做了什麼會很好。至少有幾個代碼評論? –

0
## This is my full working code for creating custom post types ## 
    function slide_init() 
    { 
     $labels = array(
      'name'     => 'Slider', 
      'singular_name'   => 'Slider', 
      'menu_name'    => 'Slider', 
      'name_admin_bar'  => 'Slider', 
      'add_new'    => 'Add New Slider', 
      'add_new_item'   => 'Add New Slider', 
      'new_item'    => 'New Slider', 
      'edit_item'    => 'Edit Slider', 
      'view_item'    => 'View Slider', 
      'all_items'    => 'All Slider Images', 
      'search items'   => 'Search Slider', 
      'parent_item_colon'  => 'Parent Slider', 
      'not_found'    => 'No Slider Found', 
      'not_found_in_trash' => 'No Slider Found In Trash', 
      ); 

     $args = array(
      'labels'    => $labels, 
      'public'    => true, 
      'publicaly_queryable' => true, 
      'show_ui'    => true, 
      'show_in_menu'   => true, 
      'query_var'    => true, 
      'rewrite'    => array('slug' => 'Slider'), 
      'capability_type'  => 'post', 
      'has_archive'   => true, 
      'Hierarchical'   => false, 
      'menu_position'   => null, 
      'menu_icon'    => 'dashicons-format-image', 
      'supports'    => array('title', 'editor', 'author', 'thumbnail', 'excerpt', 'comments','hierarchical','trackbacks','custom-fields','revisions','page-attributes'), 
      'taxonomies'   =>array('category'), 
      ); 

     register_post_type('Slider',$args); 
     register_taxonomy('Slider_category','Slider',array('hierarchical' => true, 'label' => 'Category', 'query_var' => true, 'rewrite' => array('slug' => 'slider-category'))); 
    } 
    add_action('init','slide_init'); 
0
/** Meet the team custom post 

您可以使用下面的WordPress的腳本來創建自定義後類型沒有任何插件*/

$labels = array(
    'name' => _x('Team', 'Team', 'Team') , 
    'singular_name' => _x('Team', 'Team', 'rjis') , 
    'menu_name' => _x('Meet the Team', 'admin menu', 'rjis') , 
    'name_admin_bar' => _x('Team', 'add new on admin bar', 'rjis') , 
    'add_new' => _x('Add New', 'Team', 'rjis') , 
    'add_new_item' => __('Add New Team', 'rjis') , 
    'new_item' => __('New Team', 'rjis') , 
    'edit_item' => __('Edit Team', 'rjis') , 
    'view_item' => __('View Team', 'rjis') , 
    'all_items' => __('All Team Members', 'rjis') , 
    'search_items' => __('Search Team', 'rjis') , 
    'parent_item_colon' => __('Parent Team:', 'rjis') , 
    'not_found' => __('No Team found.', 'rjis') , 
    'not_found_in_trash' => __('No Team found in Trash.', 'rjis') 
); 
    $args = array(
    'labels' => $labels, 
    'description' => __('Description.', 'Meet the team') , 
    'public' => true, 
    'publicly_queryable' => true, 
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true, 
    'rewrite' => array(
     'slug' => 'team' 
    ) , 
    'capability_type' => 'post', 
    'has_archive' => false, 
    'hierarchical' => false, 
    'menu_position' => null, 
    'supports' => array(
     'title', 
     'editor', 
     'author', 
     'thumbnail', 
     'excerpt' 
    ) , 
    'menu_icon' => PLUGIN_URL . "images/team.png" 
); 

register_post_type('team', $args); 
相關問題