2016-11-19 124 views
0

的,我想修改的职位目前的永久链接结构包括一个日期,它是在设置页面中配置,如:“/%,比去年%/%monthnum%/%天%/ %类别%/%postname%/”更改永久链接结构

一个例子公布网址:http://example.com/2016/09/11/category/child-category/long-post-slug-is-printed-here/

我的问题是,我无法弄清楚如何修改标记有特定标签的帖子这个固定链接结构,所以例如,如果我有一个标签“永久-STRUC-2”,我把它添加到我的帖子,我想那么永久改写为:http://example.com/category/child-category/long-post-slug-is-printed-here/ 的日期应该从后永久被剥离。

我使用WP滤波器 “POST_LINK”

尝试的add_filter( 'POST_LINK',阵列($此, 'change_permalink_date_structure'),1,3);

但是最终情况是,URL被改变,但是当我试图访问距离缩短的URL后,它仍然重定向到原来的 - >http://example.com/2016/09/11/category/child-category/long-post-slug-is-printed-here/

任何人都可以在这个问题上需要帮助,请?

感谢

+0

你能告诉我实际上想要存档吗? –

+0

我想更改标记为特定标记的帖子的永久链接结构 – dulesaga

+0

您目前的网址是什么? –

回答

0

你可以尝试使用htaccess的国防部重写。您必须为每个网址添加一条规则。例如:

RewriteRule /category/child-category/long-post-slug-is-printed-here/ /2016/09/11/category/child-category/long-post-slug-is-printed-here/ [L] 
+0

感谢你的这一点,但它并没有完全解决我的问题,因为要为每个需要这种例外的帖子编辑htaccess文件并不容易。 – dulesaga

0

感谢大家试图在这方面提供帮助,我设法找到了我需要的方法。基本上,我写了一个重写规则,WP用与add_rewrite_rule() 它适用于POST网址的没有日期:

$rewrite_rule_regex = '^(?!([0-9]{4})/([0-9]{1,2})/([0-9]{1,2})/)(.+?)/([^/]+)(?:/([0-9]+))?/?$'; 

add_rewrite_rule($rewrite_rule_regex, 'index.php?category_name=$matches[4]&name=$matches[5]&page=$matches[6]&istaggedcalendar=1', 'bottom'); 

而且,这种新的重写规则必须有比过去更高的优先级(通用)wp重写规则(如果我的重写规则是最后一次,并且如果它被设置为“top”,则其它一些重写规则不起作用,它不起作用):

add_filter('rewrite_rules_array',array($这,'rewrite_rulles_array_look'));

// * set the priority of our rewrite rule to not interfere with other pages 

function rewrite_rules_array_look($r_array) { 

    $rew_rule = $r_array[$this->rewrite_rule_regex]; 

    unset($r_array[$this->rewrite_rule_regex]); 

    $res = array_slice($r_array, 0, count($r_array)-1, true) + 

     array($this->rewrite_rule_regex => $rew_rule) + 

     array_slice($r_array, count($r_array)-1, count($r_array) , true) ; 


    return $res; 

}