这是我在为我的语言切换器定义的小部件区域中出现的错误:
注意:未定义的索引:代码输入 /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>';
}
}
}
}
答案 0 :(得分:0)
根据Polylang's documentation, orderby 参数仅接受 slug , name 或 id 有效值。在上面的代码中,您传递代码。
尝试更改:
$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']; }