WordPress – Qtranslate to show only available languages

I want to display in which other languages current page is translated to.

For example if current page is in english, and translation is available in french or on some other language, then script should output link to translated page in french.
If there isn’t translation available, then it should not output anything.

Read More

How this can be done.
Right now i use function <?php if (function_exists('qts_language_menu')) qts_language_menu('both'); ?> which return all languages, no matter if page have translation or no.

Related posts

Leave a Reply

2 comments

  1. I wrote this code to solve my problem. Its not pretty but it works:

    <?php
    $enabled_languages = get_option('qtranslate_enabled_languages');
    $language_names    = get_option('qtranslate_language_names');
    
    foreach ($enabled_languages as $enable_language) {
        foreach ($language_names as $lang_code => $lang_name) {
            if ($enable_language == $lang_code && $enable_language != qtrans_getLanguage()) {
                $query  = "SELECT id FROM $wpdb->posts WHERE ID = $post->ID AND $wpdb->posts.post_content LIKE '%<!--:" . $lang_code . "-->%'";
                $result = $wpdb->get_results($query);
    
                if ($result) {
                    global $qtranslate_slug;
                    echo '<a href="' . $qtranslate_slug->get_current_url($lang_code) . '">' . $lang_name . '</a>';
                }
            }
        }
    }
    ?> 
    
  2. Above code need change to work ,
    change this line :

    echo '<a href="' . $qtranslate_slug->get_current_url($lang_code) . '">' . $lang_name . '</a>';
    

    change it like this :

    echo '<a href="' . qtrans_convertURL(get_permalink(), $lang_code) . '">' . $lang_name .   '</a>';