如何为Wordpress自定义帖子类型设置自定义分类URL?

时间:2015-12-09 20:31:03

标签: php wordpress

我在插件中使用以下内容来创建自定义帖子类型:

function post_type_listing() {
    $labels = array(
        'name' => _x('Listing', 'post type general name', 'themesdojo'),
        'singular_name' => _x('Listing', 'post type singular name', 'themesdojo'),
        'add_new' => _x('Add New Listing', 'book', 'themesdojo'),
        'add_new_item' => __('Add New Listing', 'themesdojo'),
        'edit_item' => __('Edit Listing', 'themesdojo'),
        'new_item' => __('New Listing', 'themesdojo'),
        'view_item' => __('View Listing', 'themesdojo'),
        'search_items' => __('Search Listing', 'themesdojo'),
        'not_found' =>  __('No Listing found', 'themesdojo'),
        'not_found_in_trash' => __('No Listing found in Trash', 'themesdojo'), 
        'parent_item_colon' => ''
    );      
    $args = array(
        'labels' => $labels,
        'public' => true,
        'publicly_queryable' => true,
        'show_ui' => true, 
        'query_var' => true,
        //'rewrite' => true,
        'rewrite'         => array(
                'slug'          => 'view',
                'with_front'    => true
            ),
        'capability_type' => 'post',
        'hierarchical' => false,
        'menu_position' => null,
        'supports' => array('title','editor','thumbnail','author', 'comments', 'amenities'),
        'menu_icon' => 'dashicons-menu'
    );      

    register_post_type( 'item', $args );    

} 

add_action('init', 'post_type_listing');

请注意以下的自定义重写分类:

'rewrite'         => array(
                'slug'          => 'view',
                'with_front'    => true
            ),

由于某些原因,这些帖子类型仍显示http://example.com/item/%post_name%/的网址。

我很茫然。我已经保存了永久链接并清除了缓存。没有骰子。

1 个答案:

答案 0 :(得分:0)

很可能是因为一个插件改变了网址,我知道add-this插件可以做到这一点。我建议看看你安装的wordpress插件。