自定义分类页面无效

时间:2016-07-29 14:08:51

标签: wordpress custom-post-type custom-taxonomy

我创建了自定义帖子类型"目录"和注册的自定义分类和#34;目录类别"。但是无法访问分类法页面" taxonomy-directory-category.php"。获取"错误404 - 未找到"错误。

function create_post_type_listing() {
register_post_type('directory', 
    array(
        'labels' => array(
            'name' => __( 'Listings'),
                    'singular_name' => __( 'Listing'),
            'add_new' => __('Add New Listing' ),
            'add_new_item' => __('Add New Listing'),
            'edit' => __( 'Edit Listing' ),
                'edit_item' => __( 'Edit Listing' ),
                'new_item' => __( 'New listing' ),
                'view' => __( 'View Listing' ),
                'view_item' => __( 'View Listing' ),
                'search_items' => __( 'Search Listings' ),
                'not_found' => __( 'No listings found' ),
                'not_found_in_trash' => __( 'No listings found in Trash' ),
                'featured_image' => __( 'Listing Image' ),
                'set_featured_image' => __( 'Set Listing Image' ),
                'remove_featured_image' => __( 'Remove Listing Image' ),
                'use_featured_image' => __( 'Use Listing Image' )
                    ),
    'public' => true,
    'menu_position' => 5,
    'menu_icon'   => plugins_url( 'images/listing-20x20.png', __FILE__ ),
    'rewrite' => array(
        'slug' => __('directory')
    ),
    'supports' => array( 'title','editor','thumbnail')));
}

add_action( 'init', 'create_listing_taxonomies', 0 );
function create_listing_taxonomies() {
// Add new taxonomy, make it hierarchical (like categories)
$labels = array(
    'name'              => 'Listing Categories',
    'singular_name'     => 'Listing Category',
    'search_items'      => 'Listing Categories',
    'all_items'         => 'All Listing Categories',
    'parent_item'       => 'Parent Listing Category',
    'parent_item_colon' => 'Parent Listing Category:',
    'edit_item'         => 'Edit Listing Category',
    'update_item'       => 'Update Listing Category',
    'add_new_item'      => 'Add New Listing Category',
    'new_item_name'     => 'New Listing Category',
    'menu_name'         => 'Listing Category',
);

$args = array(
    'hierarchical'      => true,
    'labels'            => $labels,
    'show_ui'           => true,
    'show_admin_column' => true,
    'query_var'         => true,
    'rewrite'           => array( 'slug' => 'directory-category' ),
);

register_taxonomy( 'directory-category', array( 'directory' ), $args );
}

function listing_flush_rules() {
//defines the post type so the rules can be flushed.
create_post_type_listing();

//and flush the rules.
flush_rewrite_rules();
}
register_activation_hook(__FILE__, 'listing_flush_rules' );
add_action( 'init', 'create_post_type_listing' );

请帮助我完成分类页面结构。

此致 Shubhajeet Saha

1 个答案:

答案 0 :(得分:-1)

请将以下代码添加到您的functions.php或插件页面

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

function create_taxonomies() {
            //change  start///
            $title = 'Your title';
            $slug = 'yourslug';
            $your_plugin_textdomain = 'textdomain';
            //change  end///

            $labels = array(
                'name' => _x($title, $your_plugin_textdomain),
                'singular_name' => _x($title, $your_plugin_textdomain),
                'search_items' => __('Search Genres'),
                'all_items' => __('All ' . $title),
                'parent_item' => __('Parent ' . $title),
                'parent_item_colon' => __('Parent ' . $title . ':'),
                'edit_item' => __('Edit ' . $title),
                'update_item' => __('Update ' . $title),
                'add_new_item' => __('Add New ' . $title),
                'new_item_name' => __('New ' . $title . ' Name'),
                'menu_name' => __( ucfirst($title)),
            );

            $args = array(
                'hierarchical' => true,
                'labels' => ($labels),
                'show_ui' => true,
               // 'show_admin_column' => true,   // to display taxonomy in post table
                'query_var' => true,
                'rewrite' => array('slug' => $slug),
            );
            register_taxonomy($slug, array($catname[$key]), $args);

}