2013-10-31 97 views
0

我正在构建一个WordPress主题并希望添加自定义帖子类型。我在网上看,但似乎无法找到答案。有多个自定义帖子类型

现在我有这样的代码中的functions.php

add_action('init', 'register_cpt_tutorial'); 

function register_cpt_tutorial() { 

$labels = array( 
    'name' => _x('Tutorials', 'tutorial'), 
    'singular_name' => _x('Tutorial', 'tutorial'), 
    'add_new' => _x('Add New', 'tutorial'), 
    'add_new_item' => _x('Add New Tutorial', 'tutorial'), 
    'edit_item' => _x('Edit Tutorial', 'tutorial'), 
    'new_item' => _x('New Tutorial', 'tutorial'), 
    'view_item' => _x('View Tutorial', 'tutorial'), 
    'search_items' => _x('Search Tutorials', 'tutorial'), 
    'not_found' => _x('No tutorials found', 'tutorial'), 
    'not_found_in_trash' => _x('No tutorials found in Trash', 'tutorial'), 
    'parent_item_colon' => _x('Parent Tutorial:', 'tutorial'), 
    'menu_name' => _x('Tutorials', 'tutorial'), 
); 

$args = array( 
    'labels' => $labels, 
    'hierarchical' => false, 
    'description' => 'Tutorials description will be here', 
    'supports' => array('title', 'editor', 'thumbnail', 'comments'), 
    'taxonomies' => array('category'), 
    'public' => true, 
    'show_ui' => true, 
    'show_in_menu' => true, 
    'menu_position' => 20, 

    'show_in_nav_menus' => true, 
    'publicly_queryable' => true, 
    'exclude_from_search' => false, 
    'has_archive' => true, 
    'query_var' => true, 
    'can_export' => true, 
    'rewrite' => true, 
    'capability_type' => 'post' 
); 

register_post_type('tutorial', $args); 
} 

如果我复制粘贴此代码并修改“教程”,以“视频”它没有第二个职位类型。有人可以帮帮我吗?

+0

也更改标签 – codepixlabs

+0

对不起@wordpresser你能解释一下吗?如果我将所有的教程,教程等改为视频,视频不起作用?什么是标签? – aled2305

+0

'$标签'数组 – codepixlabs

回答

1

我会建议使用WP插件自定义文章类型UI

http://wordpress.org/plugins/custom-post-type-ui/

但如果你想使用的代码试试这个:

add_action('init', 'register_cpt_tutorial'); 

function register_cpt_tutorial() { 

$labels = array( 
    'name' => _x('Tutorials', 'tutorial'), 
    'singular_name' => _x('Tutorial', 'tutorial'), 
    'add_new' => _x('Add New', 'tutorial'), 
    'add_new_item' => _x('Add New Tutorial', 'tutorial'), 
    'edit_item' => _x('Edit Tutorial', 'tutorial'), 
    'new_item' => _x('New Tutorial', 'tutorial'), 
    'view_item' => _x('View Tutorial', 'tutorial'), 
    'search_items' => _x('Search Tutorials', 'tutorial'), 
    'not_found' => _x('No tutorials found', 'tutorial'), 
    'not_found_in_trash' => _x('No tutorials found in Trash', 'tutorial'), 
    'parent_item_colon' => _x('Parent Tutorial:', 'tutorial'), 
    'menu_name' => _x('Tutorials', 'tutorial'), 
); 

$args = array( 
    'labels' => $labels, 
    'hierarchical' => false, 
    'description' => 'Tutorials description will be here', 
    'supports' => array('title', 'editor', 'thumbnail', 'comments'), 
    'taxonomies' => array('category'), 
    'public' => true, 
    'show_ui' => true, 
    'show_in_menu' => true, 
    'menu_position' => 20, 

    'show_in_nav_menus' => true, 
    'publicly_queryable' => true, 
    'exclude_from_search' => false, 
    'has_archive' => true, 
    'query_var' => true, 
    'can_export' => true, 
    'rewrite' => true, 
    'capability_type' => 'post' 
); 
// ----- Second post type 
$labels2 = array( 
    'name' => _x('video', 'video'), 
    'singular_name' => _x('video', 'video'), 
    'add_new' => _x('Add New', 'video'), 
    'add_new_item' => _x('Add New video', 'video'), 
    'edit_item' => _x('Edit video', 'video'), 
    'new_item' => _x('New video', 'video'), 
    'view_item' => _x('View video', 'video'), 
    'search_items' => _x('Search video', 'video'), 
    'not_found' => _x('No video found', 'video'), 
    'not_found_in_trash' => _x('No video found in Trash', 'video'), 
    'parent_item_colon' => _x('Parent video:', 'tutorial'), 
    'menu_name' => _x('video', 'video'), 
); 

$args2 = array( 
    'labels' => $labels2, 
    'hierarchical' => false, 
    'description' => 'Tutorials description will be here', 
    'supports' => array('title', 'editor', 'thumbnail', 'comments'), 
    'taxonomies' => array('category'), 
    'public' => true, 
    'show_ui' => true, 
    'show_in_menu' => true, 
    'menu_position' => 20, 

    'show_in_nav_menus' => true, 
    'publicly_queryable' => true, 
    'exclude_from_search' => false, 
    'has_archive' => true, 
    'query_var' => true, 
    'can_export' => true, 
    'rewrite' => true, 
    'capability_type' => 'post' 
); 

register_post_type('tutorial', $args); 
register_post_type('video', $args2); 
} 

注意的$ args的变化 - $ args2和$标签 - $ labels2

+0

谢谢@Joe它的工作 – aled2305

相关问题