我正在尝试创建一个多语言网站。我已经将我的主页设置为static page 在我的WP管理区域。
这home page ID is 2 它会呼叫front-page.php 例如,当我在该地址的主页上时,http://examplesite.com/
所以对于法语版本,我添加了一个新的重写规则,所以我有这个url,http://examplesite.com/fr/, 它调用同一个ID为2的主页。
add_rewrite_rule(
\'^fr/?$\',
\'index.php?&p=2&lang=fr\',
\'top\'
)
但它为什么打电话
index.php 改为模板,但
not front-page.php?
我怎样才能http://examplesite.com/fr/ 调用front-page.php?
最合适的回答,由SO网友:Sally CJ 整理而成
正如我在评论中指出的,在重写规则中?&p=2 到?page_id=2. 因为p 用于查询帖子(即post 类型)。因此,对于页面(即page 类型),使用page_id.
防止http://examplesite.com/fr/ 从被重定向到http://examplesite.com/, 您可以取消规范重定向,如下所示:
add_action( \'template_redirect\', function(){
if ( is_front_page() ) {
remove_action( \'template_redirect\', \'redirect_canonical\' );
}
}, 0 );