php – WordPress,Redirects和WPML
发布时间:2020-12-13 18:04:04 所属栏目:PHP教程 来源:网络整理
导读:我有一个全新的wordpress安装,我在我的functions.php中写了一些快速重写规则,看起来像这样 – // "rewrite" /assets/xyz to /assets/?asset=xyzfunction assets_rewrite_rule($rules) { global $wp_rewrite; $asset_rule = array( // (not tested) 'assets/(
我有一个全新的wordpress安装,我在我的functions.php中写了一些快速重写规则,看起来像这样 –
// "rewrite" /assets/xyz to /assets/?asset=xyz function assets_rewrite_rule($rules) { global $wp_rewrite; $asset_rule = array( // (not tested) 'assets/(.+)/?' => 'index.php?pagename=Assets&asset=$matches[1]' ); return array_merge($asset_rule,$rules); } add_filter('page_rewrite_rules','assets_rewrite_rules'); 我用最原始的方式将我的侧边栏翻译成了WPML和字符串翻译. 这是我的侧边栏的英文部分(未翻译) – <div class="sideall"> <div class="sidebar-mai1"> <div class="sidebar-name"> <img style="width: 25px; margin-right: 10px; margin-bottom: -7px;" title="first asset" src="/wp-content/images/sidbar-assets/firstasset.png" alt="first asset" />First Asset</div> <div class="sidebar-btn"> <a class="btn-sidebar" href="/assets/first-asset/">Review</a> <a class="btn-sidebar1" href="/buy/first-asset">Trade Now!</a></div> <div style="clear: both;"></div> </div> 在尝试翻译其他语言时(比如说意大利语),wpml拒绝将我的更改保存到评论链接.就像我的重定向规则以某种方式影响它一样. 这是我添加到侧边栏的翻译 – <div class="sideall"> <div class="sidebar-mai1"> <div class="sidebar-name"> <img style="width: 25px; margin-right: 10px; margin-bottom: -7px;" title="first asset" src="/wp-content/images/sidbar-assets/firstasset.png" alt="first asset" />First Asset</div> <div class="sidebar-btn"> <a class="btn-sidebar" href="/it/assets/first-asset/">Revisione</a> <a class="btn-sidebar1" href="/buy-it/first-asset">Scambia ora!</a></div> <div style="clear: both;"></div> </div> 正如您所看到的那样,评论和购买链接都已更改..但是在我点击保存后,它只保存了我在buy href中所做的更改,但它将我的更改恢复为评论链接,并且在我之后看起来像这样保存 – <div class="sideall"> <div class="sidebar-mai1"> <div class="sidebar-name"> <img style="width: 25px; margin-right: 10px; margin-bottom: -7px;" title="first asset" src="/wp-content/images/sidbar-assets/firstasset.png" alt="first asset" />First Asset</div> <div class="sidebar-btn"> <a class="btn-sidebar" href="/it/assets">Revisione</a> <a class="btn-sidebar1" href="/buy-it/first-asset">Scambia ora!</a></div> <div style="clear: both;"></div> </div> 正如你所看到的,在我点击保存之后,它会从我的翻译中删除/ first-asset部分,现在它会导致一个空页面(/ it / assets)..我想知道它是否可能是由于改写..
另一种解决方法:
聆听客户的浏览器设置. locale_accept_from_http($_SERVER['HTTP_ACCEPT_LANGUAGE']); https://secure.php.net/manual/en/locale.acceptfromhttp.php 然后,您可以将其重写为如下函数: function my_get_langauge() { static $lang; if(is_null($lang)) { $lang = strtolower(substr($_SERVER['HTTP_ACCEPT_LANGUAGE'],2)); /** * Check list of allowed/accepted languages or revert to default */ if(!in_array($lang,['nl','en','de','it']) ) { $lang = 'en'; } } return $lang; } 这样您就不必担心语言的重定向,并且您可以接受语言,因为您的网站用户希望看到它. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |