菜单中未显示自定义分类

时间:2013-11-15 作者:Mona Coder

我试图使用Wordpress 3.7.1和PHP 5.4.12创建一个名为“News”的自定义帖子类型和一个名为“Subject”的相关分类法。我根据生成代码Generate WP 站点如下:运行代码后,我发现菜单中没有显示分类法!

enter image description here

在与代码位斗争之后,我通过删除“0”参数更新了代码挂钩操作,如下所示:

enter image description here

收件人:

enter image description here

令人惊讶的是,这次成功了!主题分类显示在菜单中

enter image description here

但我无法向分类法添加任何术语,因为我遇到了这个红框错误

enter image description here

你能告诉我我做错了什么吗?

<?php
// Register Custom Post Type
function custom_post_type_news() {
$labels = array(
    \'name\'                => \'News\',
    \'singular_name\'       => \'news\',
    \'menu_name\'           => \'News\',
    \'parent_item_colon\'   => \'Parent News:\',
    \'all_items\'           => \'All News\',
    \'view_item\'           => \'View News\',
    \'add_new_item\'        => \'Add New News\',
    \'add_new\'             => \'Add New News\',
    \'edit_item\'           => \'Edit News\',
    \'update_item\'         => \'Update News\',
    \'search_items\'        => \'Search News\',
    \'not_found\'           => \'No News Found\',
    \'not_found_in_trash\'  => \'No News Found in Trash\',
);
$args = array(
    \'label\'               => \'news\',
    \'description\'         => \'News Information Pages\',
    \'labels\'              => $labels,
    \'supports\'            => array( \'title\', \'editor\', ),
    \'taxonomies\'          => array( \'subject\' ),
    \'hierarchical\'        => false,
    \'public\'              => true,
    \'show_ui\'             => true,
    \'show_in_menu\'        => true,
    \'show_in_nav_menus\'   => true,
    \'show_in_admin_bar\'   => true,
    \'menu_position\'       => 5,
    \'menu_icon\'           => \'\',
    \'can_export\'          => true,
    \'has_archive\'         => true,
    \'exclude_from_search\' => false,
    \'publicly_queryable\'  => true,
    \'capability_type\'     => \'post\',
);
register_post_type( \'news\', $args );

}

// Hook into the \'init\' action
add_action( \'init\', \'custom_post_type_news\',0);

// Register Custom Taxonomy
function custom_taxonomy_subject()  {

$labels = array(
    \'name\'                       => \'Subjects\',
    \'singular_name\'              => \'Subject\',
    \'menu_name\'                  => \'Subject\',
    \'all_items\'                  => \'All Subjects\',
    \'parent_item\'                => \'Parent Subject\',
    \'parent_item_colon\'          => \'Parent Subject:\',
    \'new_item_name\'              => \'New Subject Name\',
    \'add_new_item\'               => \'Add New Subject\',
    \'edit_item\'                  => \'Edit Subject\',
    \'update_item\'                => \'Update Subject\',
    \'separate_items_with_commas\' => \'Separate Subject with commas\',
    \'search_items\'               => \'Search Subjects\',
    \'add_or_remove_items\'        => \'Add or remove Subjects\',
    \'choose_from_most_used\'      => \'Choose from the most used Subjects\',
);
$args = array(
    \'labels\'                     => $labels,
    \'hierarchical\'               => true,
    \'public\'                     => true,
    \'show_ui\'                    => true,
    \'show_admin_column\'          => true,
    \'show_in_nav_menus\'          => true,
    \'show_tagcloud\'              => true,
);
register_taxonomy( \'subject\', \'news\', $args );

}
// Hook into the \'init\' action
add_action( \'init\', \'custom_taxonomy_subject\', 0 );

0 个回复
结束

相关推荐