我是否可以更改Register_post_type的url

时间:2011-04-09 作者:Radek

我注册自定义邮件类型register_post_type(\'new_post\',$args); 所以新的帖子url看起来像`http://myweb.com/new_post/post_name

我可以换衣服吗_later_ 来自的url部分new_post 去别的地方?

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

如果列出$args数组会有所帮助,但您要查找的部分位于“重写”下。以下是我喜欢构建一个$args数组以注册帖子类型的方法:

// set up the labels
    $labels = array(
        \'name\' => _x(\'Archived Jobs\', \'post type general name\'),
        \'singular_name\' => _x(\'Archived Job\', \'post type singular name\'),
        \'add_new\' => __(\'Add New\'),
        \'add_new_item\' => __(\'Add New Job\'),
        \'edit_item\' => __(\'Edit Job\'),
        \'new_item\' => __(\'New Job\'),
        \'view_item\' => __(\'View Job\'),
        \'search_items\' => __(\'Search Jobs\'),
        \'not_found\' =>  __(\'No Jobs found\'),
        \'not_found_in_trash\' => __(\'No Jobs found in Trash\'), 
        \'parent_item_colon\' => \'\',
        \'menu_name\' => \'Archives\'
    );
//set up the rewrite rules
    $rewrite = array(
        \'slug\' => \'archives\'
    );
//build the arguement array
    $args = array(
        \'labels\' => $labels,
        \'public\' => true,
        \'publicly_queryable\' => true,
        \'show_ui\' => true, 
        \'show_in_menu\' => true, 
        \'query_var\' => \'archives\',
        \'rewrite\' => $rewrite,
        \'capability_type\' => \'post\',
        \'has_archive\' => true, 
        \'hierarchical\' => false,
        \'menu_position\' => null,
        \'supports\' => array(\'title\',\'editor\',\'author\',\'comments\')
    ); 
    register_post_type(\'archive\',$args);
您正在寻找的部分是$重写部分,将slug更改为您想要的任何内容(当然,url友好,没有奇怪的字符或空格)。您甚至可能希望在其中添加斜杠。在我的示例中,URL显示为:www.website。com/archives/post\\u名称/

结束

相关推荐

Changing attachment urls?

如何更改附件页URL的格式/[post-url]/[attachment-name]/ 到/media/[attachment-name]/? 我知道我可以覆盖get_attachment_link 通过attachment_link 过滤器,但我想我需要更改重定向结构,以便WordPress知道如何处理这些URL?