Polylang Switcher - Show/Hide for Widgets

时间:2015-09-29 00:42:12

标签: php if-statement

Polylang Language Switcher help please... How can I code the switcher to show/hide in the sidebar? We need to code it directly in the template with a wrapper around it. Not just add it in the widgets. Can you help me finish this IF Else statement please?

<?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
}
?>

1 个答案:

答案 0 :(得分:0)

我明白了......

<?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'] .'&nbsp;<a href ="' . $lang['url'] . '" hreflang = "' . $lang['slug'] . '">' . $lang['name'] . '</a></li>';
    }
  echo '</ul></section>';
};
?>