重写单个帖子的基本URL

时间:2013-02-08 作者:Pontus Abrahamsson

我想在查看单个帖子时附加URL。例如,当im在帖子上时,我希望url类似于:example.com/mypage/mypage/single-post-article

默认url为example.com/single-post-article

我没有在WPSE或goooglz上找到什么,但我已经读到了wp-rewrite 并且尝试过add_post_type_supportpost 但运气不好!

add_post_type_support( \'post\', array(
   \'rewrite\' => array(\'slug\' => \'/bla/bla/\')
));
我需要使用wp_rewrite?

Update

我是通过跑步来完成的register_post_type 在post\\u上再次键入“post”。但这是最好的方式吗?

  register_post_type( \'post\', array(
        \'public\'  => true,
        \'_builtin\' => false, 
        \'_edit_link\' => \'post.php?post=%d\', 
        \'capability_type\' => \'post\',
        \'map_meta_cap\' => true,
        \'hierarchical\' => false,
        \'rewrite\' => array( \'slug\' => \'/mypage/mypage\' ),
        \'query_var\' => false,
        \'pages\'     => false,
        \'supports\' => array( 
            \'title\', 
            \'editor\',
            \'author\', 
            \'thumbnail\', 
            \'excerpt\', 
            \'revisions
        ),
));

2 个回复
最合适的回答,由SO网友:Milo 整理而成

转到设置>永久链接页面,将永久链接设置为:

/mypage/mypage/%postname%/
如果不想附加类别/mypage/mypage, 您可以更改其磁导率:

function wpa85084_category_permastruct(){
    global $wp_rewrite;
    $wp_rewrite->extra_permastructs[\'category\'][\'struct\'] = \'/category/%category%\';
}
add_action( \'init\', \'wpa85084_category_permastruct\' );

SO网友:Christopher Ross

定义重写规则后,是否尝试刷新它们?

flush_rewrite_rules();

结束

相关推荐