Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author Chouby

    (@chouby)

    I am not sure I understand what you are looking for.

    The feature asked in the post you are referring to, was implemented in the template tag ‘pll_the_languages’. Maybe the documentation of the template tag is not clear enough. Here is an example to get all translations of the post reference by $post_id:
    <ul>pll_the_languages('post_id' => $post_id);</ul>

    Thread Starter QuickeneR

    (@quickener)

    Sorry, I’ll try to explain myself better.

    pll_the_languages() displays a language switcher – it is intended for the blog readers so they can choose a translation they prefer.

    I was talking about the admin panel side. Polylang already adds an option to all the widgets that lets one choose for which language that widget will be displayed. This works fine for widgets that are somewhat self-contained. Recent Posts-type widgets, on the contrary, build their contents by making their own queries to the posts table. According to polylang documentation, one can get posts in one particular language by calling
    $posts = get_posts(array(‘post_type’ => ‘post’, ‘lang’ => ‘fr’))
    This additional parameter (lang = fr) is normally absent from the queries that such widgets are issuing. I was thinking of adding polylang support to one of such widgets (Flexible Recent Posts).

    This leads to the question of how to specify the desired languages in the widget’s settings. The most simple way is to have a textbox and type ‘fr’ or ‘fr,en’ there. But it would be better to have all the currently installed languages listed and checkboxes displayed next to them. So, is there a simple way (like calling a single function) of listing the installed languages ?

    Plugin Author Chouby

    (@chouby)

    OK I better understand.
    You can use:

    global $polylang;
    if (isset($polylang))
      $languages = $polylang->get_languages_list();

    This function returns an array of ‘language’ objects (in fact these are terms of the ‘language’ taxonomy).
    $language->slug is the language code (en)
    $language->name is of course the name (English)
    $language->description is the WP locale (en_US)

    Polylang dos not directly offer a function to display checkboxes, only a function to display a dropdown box:

    $polylang->dropdown_languages();

    Hope it helps!

    Thread Starter QuickeneR

    (@quickener)

    Thank you Chouby, this looks like exactly what I need.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘[Plugin: Polylang] A function to list the installed languages ?’ is closed to new replies.