自定义POST类型默认固定链接

时间:2013-02-18 作者:Angelo A

是否可以将Wordpress设置面板中定义的permalink结构用于自定义帖子类型?如果是,我该怎么做?

我目前拥有:

function add_posts_two() {
    $labels = array(
        \'name\' => \'Poststwo\',
        \'singular_name\' => \'posttwo\',
        \'add_new\' => __(\'New Posttwo\'),
        \'add_new_item\' => __(\'New Posttwo\'),
        \'edit_item\' => __(\'Edit Posttwo\'),
        \'new_item\' => __(\'New Posttwo\'),
        \'all_items\' => __(\'All Poststwo\'),
        \'view_item\' => __(\'View Posttwo\'),
        \'search_items\' => __(\'Search Poststwo\'),
        \'not_found\' =>  __(\'No poststwo found\'),
        \'not_found_in_trash\' => __(\'No poststwo found in Trash\'),
        \'parent_item_colon\' => \'\',
        \'menu_name\' => \'Posttwo\'
    );

    $args = array(
        \'labels\' => $labels,
        \'public\' => true,
        \'publicly_queryable\' => true,
        \'show_ui\' => true,
        \'show_in_menu\' => true,
        \'query_var\' => true,
        \'rewrite\' => false,
        \'capability_type\' => \'post\',
        \'has_archive\' => true,
        \'hierarchical\' => false,
        \'taxonomies\' => array("post_tag", "category"),
        \'menu_position\' => 5,
        \'supports\' => array( \'title\', \'editor\', \'author\', \'thumbnail\', \'excerpt\', \'comments\' )
    );

    register_post_type( \'posttwo\', $args );
}
add_action( \'init\', \'add_posts_two\' );

1 个回复
最合适的回答,由SO网友:Marcin Bobowski 整理而成

尝试更改:

\'rewrite\' => false,
在$args数组中,指向:

\'rewrite\' => array(
     \'slug\' => \'posttwo\',
     \'with_front\' => false,
     \'pages\' => false
 ),
如果我对你的问题理解正确的话,应该会有帮助。

结束

相关推荐

Archive permalinks

这个网站对我学习如何使用add\\u过滤器重写永久链接非常有帮助,可以解决我们将两个博客合并为一个博客时遇到的问题。但是,我确实有一件物品我找不到任何提示:在基于日期的存档链接上,即www.domain。com/2011/12/我只是想把它们翻译成:www.domain。com/news/2011/12/提前感谢您的帮助。