-1

这是我在为语言切换器定义的小部件区域中遇到的错误:

注意:未定义索引:/HOME/DUTCHTAX/DOMAINS/DUTCHTAXADVICE.NL/PUBLIC_HTML/WP-CONTENT/THEMES/PATTI/FUNCTIONS.PHP 中的代码 835 EN

// Language Switcher for WPML
if (!function_exists('delicious_language_selector')) {
    function delicious_language_selector() {
        if (function_exists('icl_get_languages')) {
            $languages = icl_get_languages('skip_missing=0&orderby=code');
            wp_enqueue_script( 'dt-tipsy' );
            wp_enqueue_style( 'dt-tipsy' );
            if(!empty($languages)){
                echo '<div id="header_language_list"><ul>';
                    foreach($languages as $l){
                        if($l['active']) { echo '<li class="active-lang switch-lang" original-title="'.$l['native_name'].'">'; }
                            else { echo '<li class="switch-lang" original-title="'.$l['native_name'].'">'; }
                        if(!$l['active']) echo '<a href="'.$l['url'].'">';
                            if($l['code'] != 'zh-hant') { echo substr($l['native_name'], 0, 2); } else { echo $l['native_name']; }
                        if(!$l['active']) echo '</a>';
                        echo '</li>';
                    }
                echo '</ul></div>';
            }
        }
    }
}
4

1 回答 1

0

根据Polylang 的文档orderby参数仅接受slugnameid作为有效值。在上面的代码中,您传递的是code

尝试改变:

$languages = icl_get_languages('skip_missing=0&orderby=code');

至:

$languages = icl_get_languages('skip_missing=0&orderby=slug');

和:

if($l['code'] != 'zh-hant') { echo substr($l['native_name'], 0, 2); } else { echo $l['native_name']; }

至:

if($l['slug'] != 'zh-hant') { echo substr($l['native_name'], 0, 2); } else { echo $l['native_name']; }
于 2018-02-07T18:29:07.977 回答