WPML
状态
已由作者解决
解决于
Bricks 2.0
相关插件/主题
Bricks
主题标签
Compatibility

问题概述

Bricks 主题 中,当模板条件设置为仅针对特定分类项(例如特定分类目录)显示时,该条件在翻译后的模板中无法正确应用。

临时解决方法

在继续操作之前,请确保对您的站点进行完整站点备份

第一部分


  • 前往 WPML > 设置 > 自定义字段。

  • 查找 _bricks_template_settings 字段。

  • 将其设置为复制

第二部分


  • 打开主题的 functions.php 文件。

  • 添加以下代码:
    /**
     * WPML Workaround for compsupp-7667
     */
    add_filter('get_post_metadata', 'wpml_compsupp7667_bricks_translate_template_conditions', 10, 4);
    function wpml_compsupp7667_bricks_translate_template_conditions($value, $post_id, $key, $single) {
        if ($key !== '_bricks_template_settings') {
            return $value;
        }
    
        // Remove filter temporarily to avoid infinite loop
        remove_filter('get_post_metadata', 'wpml_compsupp7667_bricks_translate_template_conditions', 10);
        
        // Get all meta values
        $raw_values = get_post_meta($post_id, $key, false);
        
        // Add filter back
        add_filter('get_post_metadata', 'wpml_compsupp7667_bricks_translate_template_conditions', 10, 4);
    
        // If we have no values, return the original
        if (empty($raw_values)) {
            return $value;
        }
    
        // Process the array structure
        foreach ($raw_values as &$settings) {
            if (is_array($settings) && isset($settings['templateConditions'])) {
                foreach ($settings['templateConditions'] as &$condition) {
                    if (!empty($condition['archiveTerms']) && is_array($condition['archiveTerms'])) {
                        foreach ($condition['archiveTerms'] as &$termString) {
                            if (strpos($termString, '::') !== false) {
                                list($taxonomy, $termId) = explode('::', $termString);
                                $translatedId = apply_filters('wpml_object_id', intval($termId), $taxonomy, true);
                                if ($translatedId) {
                                    $termString = $taxonomy . '::' . $translatedId;
                                }
                            }
                        }
                    }
                }
            }
        }
    
        return $raw_values;
    }

所有已知问题 →