Initial letters with a manually inserted language switcher
-
Hi,
i won’t use a widget to put the language switcher in the header so i used this code as mentioned in the documentation:
´<?php mlp_show_linked_elements( array(‘show_current_blog’ => TRUE ) ); ?>´I want to display just the Initial letters like it is possible with the widget (DE – EN). But the above code outputs “DEUTSCH – ENGLISH”.
Is there a possibility to display only the initial letters?
Thanks,
Jochen
-
You can use
mlp_get_interlinked_permalinks(). It returns an array with some data about the translations, so you can create your own HTML output.The key is the ID of the blog, the value is an array with these values:
'post_id' => integer, 'post_title' => string, 'permalink' => URL, 'flag' => URL, 'lang' => stringThanks Toscho!
…could you tell me how i exactly do this in my case? sorry, i’m not a really a PHP crack…Something like this could work, not tested! I have no time for more, sorry.
In your theme’s
function.php:function get_translation_navigation() { $links = (array) mlp_get_interlinked_permalinks(); $login = new stdClass; if ( is_user_logged_in() ) { $login->url = wp_login_url( $_SERVER['REQUEST_URI'] ); $login->text = 'Log in'; } else { $login->url = wp_logout_url( $_SERVER['REQUEST_URI'] ); $login->text = 'Log out'; } $html = '<ul class="lang-nav">'; foreach ( $links as $link ) { $html .= sprintf( '<li><a href="%1$s" hreflang="%2$s">%3$s</a></li>', esc_url( $link['permalink'] ), esc_attr( $link['lang'] ), strtoupper( strtok( $link['lang'], '_' ) ) ); } $html .= '<li><a href="' . $login->url . '">' . $login->text . '</a></li>'; $html .= '</ul>'; return $html; }In your template call that function like this:
print get_translation_navigation();yeah, that’s close to what i wanted… i think i can modify it by myself to make it run like i need it…
thanks!
The topic ‘Initial letters with a manually inserted language switcher’ is closed to new replies.