Jump to content
Sign in to follow this  
dil_bert

Polylang-things in Wordpress: displaying a dropdown-menu and language-selector (pll_the_languages)

Recommended Posts


good day dear freaks - good day dear experts. 

the topic of today is: 
a. How to display language switcher as dropdown-menu in Polylang?
b. how to configure the widget-section the display of the language-selector?


i have installed Polylang on my wordpress-site; note: i have the following languages:

 de :: fr :: it ::es :: pt :: eng [/Code]


at the moment i don't have display as dropdown in Appereance -> Menu -> Language switcher. How can i solve it?

see here an image:

i try to achieve a customization of the language-switcher in a so called dropdown-menu 
i want to achieve the customization of the following factors: 

- color,
- size,
- font,
- border etc?

I allways thoght that i can customize in CSS, in wordpress or by some text editor in the child theme.
In appearance->menus, go in screen options on top right of the screen i should be able to check the “Language switcher” checkbox. 
here i ought to have a new metabox which should allow to add a language switcher; this should work just as we would add another menu item.


i found that in the documents: https://polylang.pro/doc/widgets/

Quote

 

 
For all widgets you have now the possibility to choose to display it for all languages (default) or only one language. 
If you select “All languages” you will have the possibility to translate the title in the Strings translation option.
Polylang adds a new widget to display a language switcher. Whatever the chosen options, the widget will display a language
only if at least one post or one page has been published in this language.

 

 

alternatively i thought that i can  use the PHP function to display it with the following code

<?php pll_the_languages( array( 'dropdown' => 1 ) ); ?>

<?php pll_the_languages( array( 'dropdown' => 1 ) ); ?>


The documentation is here - https://polylang.pro/doc/function-reference/#pll_the_languages


See i have the following languages:   

de :: fr :: it ::es :: pt :: eng 

so i accordingly need to add flags but its look like funny. Therefore i came up with a sidebar in my theme (twentyseventeen the theme with the parallax-effect), and add it to header the following code:

<div class="drop-dl">
  <a class="lang-chose" href="#"><img src=""> please now chose the language for the site - we have several ones - just choose now! </a>
  <?php get_sidebar(); ?>
</div>

susequently: in the admin page of my site i need to configure at the so called widget-section the display of the language-selector. This is needed to get a good
overview for the user of the site: Therefore i have to set up the Language-Selector to the Sidebar: that task brings up a unsorted Lists from languages.
what comes next: in the next step i add small script and css code to get this work, here is CodePen demo link

furthermore: With this (following) php code, i am trying to have more control over positioning the widget in template.


if(function_exists('pll_the_languages')){
    pll_the_languages( array( 'show_flags' => 1,'show_names' => 0  ));
}


This subsequently should help us to show up the following languages/respectively flags of nations :

 de :: fr :: it ::es :: pt :: eng  [/Code]


 

<!-- outputs a list of languages names -->
<ul>
<?php pll_the_languages(); ?>
</ul> 
<!-- outputs a flags list (without the according languages names - that is: the names of the nations) -->
<ul>
<?php pll_the_languages( array( 'show_flags' => 1,'show_names' => 0 ) ); ?>
</ul>
<!-- outputs a dropdown list of languages names -->
<?php pll_the_languages( array( 'dropdown' => 1 ) ); ?>


question: how to do this... 


can i display the language and the flag - both!?

$translations = pll_the_languages( array( 'raw' => 1 ) );


The above mentioned function will return an array of arrays, one array per language with the following entries in the array:

[id] => language id
[slug] => language code used in urls
[name] => language name
[url] => url of the translation
[flag] => url of the flag
[current_lang] => true if this is the current language, false otherwise


again: any suggestion is welcome :) Because this solution should go to  work with "Polylang widget"

above all - i am very very happy to be here at this great place...

keep up the great work  - here : it rocks!!!;)
 

poly_lang_dropdown.png

Edited by dil_bert

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Sign in to follow this  

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.