2014-06-23 100 views
0

我正在创建自定义帖子类型,它们共享我的博客的类别。我想要的是将类别名称放在永久链接上,并删除自定义文章类型名称。如何将类别置于自定义帖子类型的永久链接上

现在我有:www.mywebsite.com/ 自定义后类型名称 /后名称

而我想要的是:www.mywebsite.com/ /后名称我试图把register_post_type数组''重写'=>数组('slug'=>'%category%'),但它不起作用。结果是www.mywebsite.com/%category%/post-name

先谢谢您! (很遗憾,我的英语)


$labels = array(
    'name' => _x('Whitepaper', 'post type general name'), 
    'singular_name' => _x('Whitepaper', 'post type singular name'), 
    'add_new' => _x('Add New', 'Whitepaper'), 
    'add_new_item' => __('Add New Whitepaper'), 
    'edit_item' => __('Edit Whitepaper'), 
    'new_item' => __('New Whitepaper'), 
    'all_items' => __('All Whitepapers'), 
    'view_item' => __('View Whitepaper'), 
    'search_items' => __('Search Whitepapers'), 
    'not_found' => __('No Whitepapers found'), 
    'not_found_in_trash' => __('No Whitepapers found in Trash'), 
    'parent_item_colon' => '', 
    'menu_name' => 'Whitepapers' 
); 
$args = array(
    'labels' => $labels, 
    'public' => true, 
    'publicly_queryable' => true, 
    'show_ui' => true, 
    'show_in_menu' => true, 
    'query_var' => true, 
    'rewrite' => true, 
    'capability_type' => 'post', 
    'has_archive' => true, 
    'hierarchical' => true, 
    'menu_position' => null, 
    'supports' => array('title','editor','author','thumbnail','excerpt','comments','custom-fields'), 
    'taxonomies' => array('category'), 
    'rewrite' => array('slug' => '%category%') 
); 
register_post_type('whitepaper',$args); 

回答

0

我不认为你可以把它通过重写的说法,这是比较复杂的,你需要与端点面膜API来做到这一点。

什么是端点?

使用端点允许您轻松创建重写规则来捕获普通的WordPress网址,但最后还会多加一些额外的内容。例如,您可以使用端点来匹配后跟“gallery”的所有发布网址并显示帖子中使用的所有图像,例如example.com/my-fantastic-post/gallery/。

像这样的一个简单情况是相对容易实现与您自己的自定义重写规则。然而,端点的力量照耀更复杂的情况。如果您想识别以“gallery”结尾的帖子和网页的网址,该怎么办?如果您希望能够捕获多个不同的存档网址,例如日,月,年和类别档案,附带“xml”以便输出档案的XML表示形式?对于这些情况,端点非常有用,因为它们允许您使用单个函数调用将字符串添加到多个重写结构的末尾。

来源:make.wordpress.org/plugins/2012/06/07/rewrite-endpoints-api/

一个好的教程自定义文章类型固定链接包括使用端点

[第2] http://shibashake.com/wordpress-theme/custom-post-type-permalinks-part-2

上类的方法:

https://core.trac.wordpress.org/ticket/19275

相关问题