WordPress.org

Ready to get started?Download WordPress

Forums

Multisite Language Switcher
[resolved] Order of flags/description (15 posts)

  1. nicoeve
    Member
    Posted 12 months ago #

    Hello,
    Is it possible to change the order of the flags/description when we use this function?
    <?php if ( function_exists( 'the_msls' ) ) the_msls(); ?>

    Currently, the list is sorted by alphabetical order, except I want to choose my personalized order. ;)

    Thanks.

    https://wordpress.org/plugins/multisite-language-switcher/

  2. Dennis Ploetner
    Member
    Plugin Author

    Posted 12 months ago #

    You can sort the output by description. Look at the settings of the plugin: https://github.com/lloc/Multisite-Language-Switcher/wiki/Settings

    It is also possible to sort the output with a filter-function. Would this be more interesting for you?

  3. nicoeve
    Member
    Posted 12 months ago #

    The filter solution interested me! :D
    Because the description is displayed on the front-end.

    Thanks !

  4. Dennis Ploetner
    Member
    Plugin Author

    Posted 12 months ago #

    OK. As you know you can sort by description. A solution would be that you simply use numbers before the description for having the order you like. For example:

    1 english
    2 deutsch

    Then you can go to create a filter to hide these numbers from the output:

    function my_msls_output_get( $url, $link, $current ) {
        return sprintf(
            '<a href="%s" title="%s"%s>%s</a>',
            $url,
            substr( $link->txt, 2),
            ( $current ? ' class="current"' : '' ),
            $link
        );
    }
    add_filter( 'msls_output_get', 'my_msls_output_get', 10, 3 );
  5. nicoeve
    Member
    Posted 12 months ago #

    Thank you! It works.

    Suggestion: It would be nice, in a future update, to add functionality where you could drag and drop the different languages ​​to its own order. :)

  6. Dennis Ploetner
    Member
    Plugin Author

    Posted 12 months ago #

    Yeah, there is still a lot to do. ;)

  7. nicoeve
    Member
    Posted 12 months ago #

    I think so. :)

  8. nicoeve
    Member
    Posted 11 months ago #

    Additional question:
    Is it possible to make the same filter on the description? (for substr)

  9. Dennis Ploetner
    Member
    Plugin Author

    Posted 11 months ago #

    $link is an object so this is not possibile in an easy way.

  10. nicoeve
    Member
    Posted 11 months ago #

    The hard way do not scare me! :)

  11. Dennis Ploetner
    Member
    Plugin Author

    Posted 11 months ago #

    This is not what I meant. It makes no sence to do it that way and the result would be equal. ;) Maybe if you can describe a little bit more what you want to do...

  12. nicoeve
    Member
    Posted 11 months ago #

    At first I did not want to display the description (only the flag).
    But now, yes (flag + description).

    So I have:
    "1 Français"
    "2 English"
    "3 Deutsch"

    I want to delete the number (in the front-end) that I use to choose the order of the country.

  13. Dennis Ploetner
    Member
    Plugin Author

    Posted 11 months ago #

  14. nicoeve
    Member
    Posted 11 months ago #

    To test MslsOutput, I tried this :

    <?php
    $display = 0;
    $exists  = false;
    $obj     = new MslsOutput();
    
    foreach ( $obj->get( $display, $exists ) as $link ) {
    	echo $link->description;
    }
    ?>

    But it does not work. :(
    This is because the object is in a "protected" mode.

  15. Dennis Ploetner
    Member
    Plugin Author

    Posted 11 months ago #

    You should print out the object to "test" it as in my example. You can create your own link object by extending MslsLink and returning an object of this type with a filter attached to msls_link_create.

    But this is a complete other story ... please open a new thread for that.

    BTW MslsLink has just one property: $format_string but a method called get_description.

Reply

You must log in to post.

About this Plugin

About this Topic