- 状态
- 已解决
- 报告针对
- WPML Multilingual CMS 3.1.9.5
- 解决于
- 3.2
问题概述
当一个或多个父页面具有别名相同的不同子页面时,打开其中一个子页面会重定向到错误的页面。
在子页面中重复使用别名似乎会导致前端的重定向错误。
示例:
- Page A
- child-aa
- child-ab
- Page B
- child-aa(独立页面,但别名与 1.1 相同)
- child-bb
临时解决方法
此问题将在 WPML 3.2 中得到修复。
在此期间,您可以使用以下临时解决方法。
请注意,这仅适用于重复的子页面别名,前提是父页面未使用与子页面相同的名称。
- 对您的网站进行完整备份。如果可能,请先在非生产环境的网站副本中进行尝试。
- 打开
sitepress.class.php - 转到第 7804 行:它应该只包含
// Adjust page name - 将此代码区块(第 7804 行到第 7828 行):
// Adjust page name if ( isset( $q->query_vars[ 'pagename' ] ) && !empty( $q->query_vars[ 'pagename' ] ) ) { // find the page with the page name in the current language. $pagename = explode ( '/', $q->query_vars[ 'pagename' ] ); $pagename = array_pop ( $pagename ); $pid = $wpdb->get_var( $wpdb->prepare( " SELECT ID FROM $wpdb->posts p JOIN {$wpdb->prefix}icl_translations t ON p.ID = t.element_id AND t.element_type='post_page' WHERE p.post_name=%s AND t.language_code = %s ", $pagename, $current_language ) ); if ( $pid ) { $q->query_vars[ 'page_id' ] = $pid; // We have found the page id unset( $q->query_vars[ 'pagename' ] ); if ( $q->query_vars[ 'page_id' ] == get_option( 'page_for_posts' ) ) { // it's the blog page. $q->is_page = false; // $wp_query->is_page = false; $q->is_home = true; // $wp_query->is_home = true; $q->is_posts_page = true; // $wp_query->is_posts_page = true; } } }
替换为该区块:// Adjust page name if ( isset( $q->query_vars[ 'pagename' ] ) && !empty( $q->query_vars[ 'pagename' ] ) ) { // find the page with the page name in the current language. $pid = $wpdb->get_var( $wpdb->prepare( " SELECT ID FROM $wpdb->posts p JOIN {$wpdb->prefix}icl_translations t ON p.ID = t.element_id AND element_type='post_page' WHERE p.post_name=%s AND t.language_code = %s ", $q->query_vars[ 'pagename' ], $current_language ) ); if ( $pid ) { $q->query_vars[ 'page_id' ] = $pid; // We have found the page id unset( $q->query_vars[ 'pagename' ] ); if ( $q->query_vars[ 'page_id' ] == get_option( 'page_for_posts' ) ) { // it's the blog page. $q->is_page = false; // $wp_query->is_page = false; $q->is_home = true; // $wp_query->is_home = true; $q->is_posts_page = true; // $wp_query->is_posts_page = true; } } } - 保存
- 重新加载网站