WordPress.org

Forums

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

  1. nicoeve
    Member
    Posted 1 year 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 1 year 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 1 year ago #

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

    Thanks !

  4. Dennis Ploetner
    Member
    Plugin Author

    Posted 1 year 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 1 year 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 1 year ago #

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

  7. nicoeve
    Member
    Posted 1 year ago #

    I think so. :)

  8. nicoeve
    Member
    Posted 1 year ago #

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

  9. Dennis Ploetner
    Member
    Plugin Author

    Posted 1 year ago #

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

  10. nicoeve
    Member
    Posted 1 year ago #

    The hard way do not scare me! :)

  11. Dennis Ploetner
    Member
    Plugin Author

    Posted 1 year 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 1 year 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 1 year ago #

  14. nicoeve
    Member
    Posted 1 year 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 1 year 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.

Topic Closed

This topic has been closed to new replies.

About this Plugin

  • Multisite Language Switcher
  • Frequently Asked Questions
  • Support Threads
  • Reviews

About this Topic