admin管理员组文章数量:1130349
I want to change the structure of yearly/monthly archive URL of default post type 'post'.
As we know be default the URLs are like:
Default:
but want them rewritten, so end up like this:
New:
i tried following but do seem to work:
add_rewrite_rule("about/blog/archive/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=post&year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/([0-9]{2})/?",'index.php?post_type=post&year=$matches[1]&monthnum=$matches[2]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/page/?([0-9]{1,})/?",'index.php?post_type=post&year=$matches[1]&paged=$matches[2]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/?",'index.php?post_type=post&year=$matches[1]','top');
I'd like someone to point to the right direction, need more info do leave a comment.
thanks.
I want to change the structure of yearly/monthly archive URL of default post type 'post'.
As we know be default the URLs are like:
Default: http://wwww.domain/2013/09
but want them rewritten, so end up like this:
New: http://wwww.domain/about/blog/archive/2013/09
i tried following but do seem to work:
add_rewrite_rule("about/blog/archive/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=post&year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/([0-9]{2})/?",'index.php?post_type=post&year=$matches[1]&monthnum=$matches[2]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/page/?([0-9]{1,})/?",'index.php?post_type=post&year=$matches[1]&paged=$matches[2]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/?",'index.php?post_type=post&year=$matches[1]','top');
I'd like someone to point to the right direction, need more info do leave a comment.
thanks.
Share Improve this question asked Sep 28, 2013 at 13:03 TheDeveloperTheDeveloper 2684 silver badges10 bronze badges1 Answer
Reset to default 2You can do this without adding rewrite rules by changing the $date_structure of the $wp_rewrite instance of the WP_Rewrite class:
function wpa116030_init(){
global $wp_rewrite;
$wp_rewrite->date_structure = 'about/blog/archive/%year%/%monthnum%/%day%';
}
add_action( 'init', 'wpa116030_init' );
Visit your Permalinks settings page after adding this code to flush the rewrite rules.
I want to change the structure of yearly/monthly archive URL of default post type 'post'.
As we know be default the URLs are like:
Default:
but want them rewritten, so end up like this:
New:
i tried following but do seem to work:
add_rewrite_rule("about/blog/archive/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=post&year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/([0-9]{2})/?",'index.php?post_type=post&year=$matches[1]&monthnum=$matches[2]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/page/?([0-9]{1,})/?",'index.php?post_type=post&year=$matches[1]&paged=$matches[2]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/?",'index.php?post_type=post&year=$matches[1]','top');
I'd like someone to point to the right direction, need more info do leave a comment.
thanks.
I want to change the structure of yearly/monthly archive URL of default post type 'post'.
As we know be default the URLs are like:
Default: http://wwww.domain/2013/09
but want them rewritten, so end up like this:
New: http://wwww.domain/about/blog/archive/2013/09
i tried following but do seem to work:
add_rewrite_rule("about/blog/archive/([0-9]{4})/([0-9]{2})/page/?([0-9]{1,})/?",'index.php?post_type=post&year=$matches[1]&monthnum=$matches[2]&paged=$matches[3]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/([0-9]{2})/?",'index.php?post_type=post&year=$matches[1]&monthnum=$matches[2]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/page/?([0-9]{1,})/?",'index.php?post_type=post&year=$matches[1]&paged=$matches[2]','top');
add_rewrite_rule("about/blog/archive/([0-9]{4})/?",'index.php?post_type=post&year=$matches[1]','top');
I'd like someone to point to the right direction, need more info do leave a comment.
thanks.
Share Improve this question asked Sep 28, 2013 at 13:03 TheDeveloperTheDeveloper 2684 silver badges10 bronze badges1 Answer
Reset to default 2You can do this without adding rewrite rules by changing the $date_structure of the $wp_rewrite instance of the WP_Rewrite class:
function wpa116030_init(){
global $wp_rewrite;
$wp_rewrite->date_structure = 'about/blog/archive/%year%/%monthnum%/%day%';
}
add_action( 'init', 'wpa116030_init' );
Visit your Permalinks settings page after adding this code to flush the rewrite rules.
本文标签: url rewritingRewrite urlpermalink for default archiveyearlymonthly
版权声明:本文标题:url rewriting - Rewrite urlpermalink for default archive - yearlymonthly 内容由热心网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:https://it.en369.cn/questions/1749079375a2312808.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。


发表评论