WordPress.org

Ready to get started?Download WordPress

Forums

qTranslate
qtranslate flags in header (10 posts)

  1. benisv
    Member
    Posted 10 months ago #

    Hi i have install qtranslate and from this post i manage to add the language links to my header but i can manage to add flags img to the links .
    This is my site here : http://likeadot.com/

    http://wordpress.org/support/topic/add-qtranslate-langs-to-header?replies=6

    #1
    So i add to header.php this code :

    <?php
      global $q_config;
      if(is_404()) $url = get_option('home'); else $url = '';
      echo '<ul id="headerMenuSystem">';
    
      foreach(qtrans_getSortedLanguages() as $language)
      {
        $link = qtrans_convertURL('', $language);
    
        if($_SERVER["HTTPS"] == "on")
          $link = preg_replace('#^http://#','https://', $link);
    
        echo '<li class="menu_item"><a href="'.$link.'"';
        echo ' hreflang="'.$language.'" title="'.$q_config['language_name'][$language].'"';
        echo '><span';
        echo '>'.$q_config['language_name'][$language].'</span></a></li>';
      }
    
      echo '</ul>';
    ?>

    and it the custom css i add this:

    #headerMenuSystem { list-style: none; }
    #headerMenuSystem li { float:right; width:auto; padding:0 20px 0 0; }

    In that post "kvspublic" said to

    add "img" tag before "span"

    . but i do not know where to add this ,so can anyone help me with this?

    #2

    How can i invert the order of the languages ? "English" to left and "Romana" to right

    Thank you all

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

    [No bumping. If it's that urgent, consider hiring someone.]

  2. sanderbontje
    Member
    Posted 9 months ago #

    I use the small function below to create a div with only the language flags. You might be able to adapt it to your needs:

    // Language Select Code for non-Widget users
    function mwo_qtrans_language_flags_menu() {
    	if ( !function_exists( "qtrans_getSortedLanguages" ) ) {
    		// plugin qTranslate must be active
    		echo '<!-- Please activate the qTranslate plugin -->';
    		return;
    	}
    	global $q_config;
    	if( is_404() ) {
    		$url = get_option( 'home' );
    	} else {
    		$url = '';
    	}
    	$languages = qtrans_getSortedLanguages( true );
    	foreach($languages as $language) {
    		$classes = array( 'language', 'lang-'.$language );
    		// add an extra style class to the active language
    		if( $language == $q_config[ 'language' ] ) {
    			$classes[] = 'active';
    		}
    		echo '<div class="'. implode(' ', $classes) .'"><a href="'.qtrans_convertURL( $url, $language ).'"';
    		echo ' hreflang="' . $language . '" title="' . $q_config[ 'language_name' ][ $language ] . '">';
    		echo '<img src="' . get_stylesheet_directory_uri() . '/images/flags/' . $language . '.png" alt="' . $q_config[ 'language_name' ][ $language ] . '" /></a></div>' . "\n";
    	}
    }
  3. Prolet
    Member
    Posted 9 months ago #

    benisv, I see you didn't succeed to put pics on your language links.
    sanderbontje, I tried to use your code, but it shows on the page, after saving.
    Is there something you will suggest to add/remove in it, please?
    Thank you!

  4. sanderbontje
    Member
    Posted 9 months ago #

    What shows on the page? The code? Did you put it inside PHP tags? Please be more specific when you ask for help.

  5. Prolet
    Member
    Posted 9 months ago #

    sanderbontje, you actually gave me the answer :)
    I didn't put the php tags. I just blindly copy/pasted the code.
    Now I;ll try it agin and I'll give you a feedback.
    Thanks!

  6. Prolet
    Member
    Posted 9 months ago #

    Nothing happened.I mean It didn't show flags on the page.
    Thank you for your time anyway :)

  7. sanderbontje
    Member
    Posted 9 months ago #

    That snippet of code outputs img tags, the src is pointing to an subfolder of your theme. So you have to make sure that those images exist. For example <your-theme-dir>/images/flags/nl.png for Dutch. Adapt the code to fit your own theme design.

    When you look at the generated HTML source of your page, can you see the img tags being printed?

  8. Prolet
    Member
    Posted 9 months ago #

    Dear sanderbontje,
    I'm thrilled by your help! It's no easy to teach others and be tolerant!

    I made it :)

    heres what I found and works perfect:

    In header.php added
    echo "<div style='position:relative; margin-left:200px; padding-top:15px;'>";
    echo qtrans_generateLanguageSelectCode('both');
    echo "</div>";

    Then in the Quick CSS added:
    .qtrans_language_chooser li { float: left; position: relative; display: inline; padding-right: 6px; padding-top:3px; }
    a.qtrans_flag:hover {background-position: -18px 0 ; }

    Thank you for your time :)

  9. sanderbontje
    Member
    Posted 9 months ago #

    No problem, glad it worked out!

  10. mtraps
    Member
    Posted 1 week ago #

    Thanks for the help!

Reply

You must log in to post.

About this Plugin

About this Topic