- 状态
- 已解决
- 解决于
- WPML Multilingual CMS 4.7.4
- 相关插件/主题
- Elementor
- 主题标签
- Compatibility
问题概述
当将 Elementor Pro 的 Loop Grid 与备用模板一起使用时,在循环模板中翻译的非动态内容在前端无法以正确的语言显示。出现此问题的原因是备用模板 ID 未被翻译。
临时解决方法
请确保在继续操作之前对您的站点进行完整备份。
- 打开主题的functions.php文件。
- 添加以下代码:
// WPML Workaround for compsupp-6865 add_filter('elementor/frontend/before_render', 'wpml_compsupp6865_filter_loop_grid_widget'); function wpml_compsupp6865_filter_loop_grid_widget($element) { if ('loop-grid' !== $element->get_name()) { return $element; } $settings = $element->get_settings(); if (!isset($settings['alternate_templates']) || !is_array($settings['alternate_templates'])) { return $element; } $alternate_settings = $settings['alternate_templates']; foreach ($alternate_settings as $key => $value) { if (empty($value['template_id']) || !is_numeric($value['template_id'])) { continue; } // Use apply_filters to adjust template_id for WPML $id = apply_filters('wpml_object_id', $value['template_id'], get_post_type($value['template_id']), true); if (!is_numeric($id)) { continue; } // Update the template_id in alternate_settings $alternate_settings[$key]['template_id'] = $id; } // Update the settings with the modified alternate_templates $settings['alternate_templates'] = $alternate_settings; $element->set_settings('alternate_templates', $settings['alternate_templates']); }