Polylang语言切换器帮助…如何编写切换器以在侧边栏中显示/隐藏?我们需要在模板中使用包装器直接对其进行编码。而不仅仅是添加到小部件中。你能帮我完成这个IF Else语句吗?
<?php
if ( ????? ) { // if translations in the site exists show language switcher
if (get_locale() == 'en_US') {
echo '<section class="widget widget-related-content custom-sidebar<h3>Translation</h3>
';
} else {
echo '<section class="widget widget-related-content custom-sidebar<h3>'.pll__('Translation').'</h3>
';
}
pll_the_languages(
array('show_flags'=>1,
'show_names'=>1,
'hide_current'=> 1,
'hide_if_empty' => 1,
'force_home' => 0,
'hide_if_no_translation' => 1));
echo '
</section>';
} else {
// DO NOT SHOW ANYTHING
}
?>
I figure out…
<?php
$languages = pll_the_languages(array(
'show_flags'=> 1,
'raw' => 1,
'hide_if_no_translation' => 1,
'show_names'=> 1,
'hide_current'=> 1,
'hide_if_empty' => 1,
'force_home' => 0,
'hide_if_no_translation' => 1
));
if ($languages == true ){
if (get_locale() == 'en_US') {
echo '<section class="widget widget-related-content custom-sidebar"><h3>Translation</h3><ul>';
} else {
echo '<section class="widget widget-related-content custom-sidebar"><h3>'.pll__('Translation').'</h3><ul>';
}
foreach ($languages as $lang) {
echo '<li>'. $lang['flag'] .' <a href ="' . $lang['url'] . '" hreflang = "' . $lang['slug'] . '">' . $lang['name'] . '</a></li>';
}
echo '</ul></section>';
};
?>