WordPress.org

Ready to get started?Download WordPress

Forums

Polylang
[resolved] Tweak for better styling of flags (3 posts)

  1. David Szego
    Member
    Posted 1 year ago #

    In include/core.php around line 847, you'll find a foreach() which outputs the flag of a language as a list item.

    Unfortunately, there is no ol or ul (un/ordered list) tag surrounding the li (list items), so you can't style them as a group without affecting other list items in the current block.

    This can be corrected by adding the li tag as a wrapper around the foreach, like this:

    else {
                            $output = '';
    
                            $output = '<ul class="polylangFlags">';
    
                            foreach ($this->get_languages_list(array('hide_empty' => $hide_if_empty)) as $language) {
                                    // hide current language
                                    if ($this->curlang->term_id == $language->term_id && $hide_current)
    
    ... bunch of stuff in the foreach loop ...
    
                                    $output .= sprintf("<li class='%s'><a hreflang='%s' href='%s'>%s</a></li>\n",
                                            $class, esc_attr($language->slug), esc_url($url), $show_flags && $show_names ? $flag.'&nbsp;'.$name : $flag.$name);
                            }
    
                            $output .= "</ul>";
    
                    }

    This also allows the flag list to be specifically styled, by use of the class "polylangFlags".

    Of course, you can tweak this to your liking!

    I hope it gets included in the next version, I do love this plugin! I'll be using it heavily in my Talmud Wiki at http://www.talmud-wiki.org

    Cheers,
    David Szego

    http://wordpress.org/extend/plugins/polylang/

  2. Chouby
    Member
    Plugin Author

    Posted 1 year ago #

    Hello David!

    It is not likely that I change this. The reason is that I want to be consitent with similar function of the WordPress core: http://codex.wordpress.org/Template_Tags/wp_list_categories

    And as a matter of fact, you can obtain exactly the same result without modifying the function. For example:

    <ul class="polylangFlags"><?php pll_the_languages('show_flags' => 1); ?></ul>
  3. David Szego
    Member
    Posted 1 year ago #

    I like your solution better! Thanks!!

Topic Closed

This topic has been closed to new replies.

About this Plugin

About this Topic