Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Template tag: Displays links to the current page in other languages
- // Usage: do_action('the_languages');
- function the_languages($args = '') {
- $defaults = array(
- 'dropdown' => 0, // display as list and not as dropdown
- 'show_names' => 1, // show language names
- 'show_flags' => 0, // don't show flags
- 'hide_if_empty' => 1 // hides languages with no posts (or pages)
- );
- extract(wp_parse_args($args, $defaults));
- $listlanguages = $this->get_languages_list($hide_if_empty);
- $output = $dropdown ? '<select name="lang_choice" id="lang_choice" onchange="window.location.href=this.options[this.selectedIndex].value">' : "<ul>\n";
- foreach ($listlanguages as $language) {
- $url = $this->get_translation_url($language);
- $url = isset($url) ? $url : $this->get_home_url($language); // if the page is not translated, link to the home page
- $class = 'lang-item lang-item-'.esc_attr($language->term_id);
- if ($language->slug == $this->curlang->slug)
- $class .= ' current-lang';
- $flag = $show_flags &&
- file_exists(POLYLANG_DIR.($file = '/local_flags/'.$language->description.'.png')) ||
- file_exists(POLYLANG_DIR.($file = '/flags/'.$language->description.'.png')) ?
- '<img src="'.WP_PLUGIN_URL.'/polylang'.$file.'" alt="'.$language->name.'" />' : '';
- $name = $show_names || !$show_flags ? esc_attr($language->name) : '';
- $output .= $dropdown ?
- sprintf(
- "<option value='%s'%s>%s</option>\n",
- $url,
- $language->slug == $this->curlang->slug ? ' selected="selected"' : '',
- $name // FIXME flag does not work for the dropdown list
- ) :
- '<li class="'.$class.'"><a href="'.$url.'">'.($show_flags && $show_names ? $flag.' '.$name : $name)."</a></li>\n";
- }
- $output .= $dropdown ? '</select>' : "</ul>\n";
- echo $output;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement