Wizhi CMS 文档

快速添加分类方法(分类法)

为什么要使用分类法

现实生活中的每种事物都会有很多种分类方法,比如“图书”可以按照年代、类型、语言、地域等方法分类;“产品” 可以按照颜色、尺码、产地等方法来分类。

使用不同的分类方法把内容归类,可以帮助用户更方便的查找内容。

添加文章类型和分类法的方法

添加之前,首先判断功能时是否存在,以免禁用或未安装插件时出现错误。

其中pro是保存在数据库中的文章类型的名称,通过这个字段区分不同的文章类型。‘产品’是显示在后台菜单中的名称。

if ( function_exists ("wizhi_create_types") and function_exists ("wizhi_create_taxs") ) {
        wizhi_create_types( "pro", "产品", array( 'title', 'editor', 'author', 'thumbnail', 'comments' ), true );
        wizhi_create_taxs( "procat", 'pro', "产品分类" );

        wizhi_create_types( "slider", "幻灯", array( 'title', 'thumbnail' ), true );
}

把以上代码加入到主题的function.php即可。

添加已注册的分类方法到文章类型

有时候,两个文章类型可能需要共用一个分类方法,而分类方法只能注册一次,这种情况下,我们只需要把已经注册的分类方法添加到现有的文章类型就可以了。

add_action('init','wizhi_add_categories_to_page');
function wizhi_add_categories_to_page(){
    register_taxonomy_for_object_type('category', 'page');
}

为自定义分类方法添加设置支持

默认的自定义分类方法除了固有的几个字段,是没有太多设置的,可以通过以下方法为自定义分类方法添加设置。

add_filter( 'wizhi_taxonomy_setting_supports', 'enter_add_tax_settings', 10, 3 );
function enter_add_tax_settings($taxonomies) {
    $taxonomies[] = 'show_cat';
    $taxonomies[] = 'course_cat';

    return $taxonomies;
}