分类法不起作用 [英] Taxonomy is not working

查看:26
本文介绍了分类法不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我创建了一个名为 blogs 的帖子类型和一个名为blog name"的分类法...帖子按类别显示,但在分类法中帖子未显示.

I have created a post type called blogs with categories and a taxaonomy called "blog name"... Posts are showing in categories but in taxonomies posts are not shown.

我是分类学的新手...我已将代码粘贴在这里

I am new to taxanomies... I have pasted the code here

function create_post_type_blogs() {

    $labels = array(
        'name' => _x('Blog Posts', 'post type general name', THEMEDOMAIN),
        'singular_name' => _x('Posts', 'post type singular name', THEMEDOMAIN),
        'add_new' => _x('Add New Post ', 'book', THEMEDOMAIN),
        'add_new_item' => __('Add New Post', THEMEDOMAIN),
        'edit_item' => __('Edit Post', THEMEDOMAIN),
        'new_item' => __('New Post', THEMEDOMAIN),
        'view_item' => __('View Posts', THEMEDOMAIN),
        'search_items' => __('Search Posts', THEMEDOMAIN),
        'not_found' =>  __('No Posts found', THEMEDOMAIN),
        'not_found_in_trash' => __('No Posts found in Trash', THEMEDOMAIN), 
        'parent_item_colon' => ''
    );      
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'query_var' => true,
        'rewrite' => true,
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor', 'thumbnail', 'comments','author'),
        'taxonomies'  => array( 'blogname', 'category', 'post_tag' ),
        'menu_icon' => get_stylesheet_directory_uri().'/functions/images/sign.png'
    );




    register_post_type( 'blogs', $args );
} 


add_action('init', 'create_post_type_blogs', 0 );


// Register Custom Taxonomy
function add_taxonomy_blogname()  {
    $labels = array(
        'name'                       => 'Blog Name',
        'singular_name'              => 'Blog Name',
        'menu_name'                  => 'Blog Name',
        'all_items'                  => 'All Blog Names',
        'new_item_name'              => 'New Blog Name',
        'add_new_item'               => 'Add New Blog Name',
        'edit_item'                  => 'Edit Blog Name',
        'update_item'                => 'Update Blog Name',
        'separate_items_with_commas' => 'Separate Blog Name with commas',
        'search_items'               => 'Search Blog Name',
        'add_or_remove_items'        => 'Add or remove Blog Name',
        'choose_from_most_used'      => 'Choose from the most used Blog Name'

    );
    $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( 'blogname', 'blogs', $args );
}

add_action( 'init', 'add_taxonomy_blogname', 0 );

推荐答案

将此代码添加到您的 function.php &生成博客自定义帖子类型

add_action( 'init', 'create_blog_post_type' );

function create_blog_post_type() {

register_post_type( 'blog',

array(

    'labels' => array(

        'name' => _x( 'Blog', 'post type general name', 'livepulse' ),

        'singular_name' => __( 'Blog', 'post type singular name', 'livepulse' ),

        'add_new' => _x('Add New', 'blog', 'livepulse' ),

        'add_new_item' => __('Add New', 'livepulse' ),

        'edit_item' => __('Edit', 'livepulse' ),

        'new_item' => __('New', 'livepulse' ),

        'all_items' => __('View Posts'),

        'view_item' => __('View', 'livepulse' ),

        'search_items' => __('Search', 'livepulse' ),

        'not_found' =>  __('No post found', 'livepulse' ),

        'not_found_in_trash' => __('No post found in Trash', 'livepulse' ), 

        'parent_item_colon' => '',

        'menu_name' => _x( 'Blog', 'livepulse' ),

    ),

    'public' => true,

    'has_archive' => true,

    'rewrite' => array('slug' => 'blog'),

    'supports' => array('title','editor','thumbnail','page-attributes','comments'),


));
flush_rewrite_rules();

register_taxonomy('blog_category','blog',

array(

    'hierarchical' => false,

    'labels' => array(

        'name' => _x( 'Categories', 'taxonomy general name', 'livepulse' ),

        'singular_name' => _x( 'Blog', 'taxonomy singular name', 'livepulse' ),

        'search_items' =>  __( 'Search Blog', 'livepulse' ),

        'popular_items' => __( 'Popular Blog', 'livepulse' ),

        'all_items' => __( 'All Categories', 'livepulse' ),

        'parent_item' => null,

        'parent_item_colon' => null,

        'edit_item' => __( 'Edit Blog', 'livepulse' ), 

        'update_item' => __( 'Update Blog', 'livepulse' ),

        'add_new_item' => __( 'Add New Categories', 'livepulse' ),

        'new_item_name' => __( 'New Blog Name', 'livepulse' ),

        'separate_items_with_commas' => __( 'Separate Blog with commas', 'livepulse' ),

        'add_or_remove_items' => __( 'Add or remove Blog', 'livepulse' ),

        'choose_from_most_used' => __( 'Choose from the most used Blog', 'livepulse' )

    ),

    'hierarchical' => true,

    'query_var' => true,
    'rewrite' => array('slug' => 'blogascategory'),
)

);
flush_rewrite_rules();

register_taxonomy('blog-tag',array('blog'),
array
(
'hierarchical' => false,
'labels' => array
(
    'name' => _x( 'Tags', 'taxonomy general name' ),
    'singular_name' => _x( 'blog', 'taxonomy singular name' ),
    'search_items' =>  __( 'Search Tags' ),
    'all_items' => __( 'All Tags' ),
    'edit_item' => __( 'Edit Tag' ), 
    'update_item' => __( 'Update Tag' ),
    'add_new_item' => __( 'Add New Tag' ),
    'new_item_name' => __( 'New Tag Name' ),
    'menu_name' => __( 'Tags' ),
),
'show_ui' => true,
'query_var' => true,
'rewrite' => array('slug' => 'blog-tag', 'with_front' => true),
)
);
flush_rewrite_rules();
}

这篇关于分类法不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆