Advertisement
sarahn

horizontal language selector - function call in template

Jan 13th, 2014
212
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.58 KB | None | 0 0
  1. /**
  2. * Inline (horizontal) custom language selector
  3. *
  4. * To use call wpml_custom_language_selector(); in a template
  5. * Note: Take the time to study the output code.
  6. */
  7. function wpml_custom_language_selector(){
  8. // check if wpml is installed
  9. if (function_exists('icl_get_languages')) {
  10. // get active languages. Available params here:
  11. // http://wpml.org/documentation/getting-started-guide/language-setup/custom-language-switcher/
  12. $languages = icl_get_languages('skip_missing=0&orderby=code&order=desc');
  13. if(!empty($languages)){
  14. echo '<div class="lang_selector">';
  15. foreach($languages as $l){
  16. // from this point on, uncomment whatever output you like
  17. // flags only - do not display current language
  18. /* if(!$l['active']){
  19. echo '<a href="'.$l['url'].'">
  20. <img src="'.$l['country_flag_url'].'" alt="'.$l['language_code'].'" />
  21. </a>';
  22. } */
  23.  
  24. // the output code options below will display the current language
  25. // this adds an "active" class to the current language anchor
  26. $class = $l['active'] ? ' class="active"' : NULL;
  27. // code only
  28. /*$langs .= '<a ' . $class . ' href="'.$l['url'].'">' . strtoupper ($l['language_code']). '</a> | ';*/
  29. //flag-code divided by a |
  30. /*$langs .= '<a ' . $class . ' href="' . $l['url'] . '"><img src="' . $l['country_flag_url'] . '" alt="' . $l['language_code'] . '" />' . strtoupper ($l['language_code']). '</a> | ';*/
  31. }
  32. // strip the empty space and | from last language
  33. $langs = substr($langs,0,-3);
  34. echo $langs;
  35. echo '</div>';
  36. }
  37. }
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement