qTranslate plugin switching language in the same page
Solution 1
I'm using qTranslate on my project and I do not do any of that stuff you do in your code above and have no problem switching between languages.
All I do is call qts_language_menu()
function that creates language menu, nothing else. This will create necessary links which ables you to switch between languages but stay on the same page.
Solution 2
You don't need to use get_permalink()
you can just pass an empty string as url and the language as 2nd param and the function will do rest ! just like:
$my_translated_content_url = qtrans_convertURL("", "en");
infact if you see at the function definition:
function qtrans_convertURL($url='', $lang='', $forceadmin = false) {
global $q_config;
// invalid language
if($url=='') $url = esc_url($q_config['url_info']['url']); // <-You don't need the url
if($lang=='') $lang = $q_config['language'];
[... the function continue...]
Related videos on Youtube
markobarna
Updated on June 04, 2022Comments
-
markobarna almost 2 years
I have a serious problem with a qTranslate buttons.
Right now the web structure is:http://www.site.com/news/?lang=en
When I stay in the home page and I try to change the language, the botton opens the first post (maybe because I'm using permalink):
<?php if(qtrans_getLanguage()=='it'): ?> <li><a href="<?php echo qtrans_convertURL(get_permalink(), 'en'); ?>" >eng</a></li> <li class="liguaattiva">ita</li> <?php endif; ?> <?php if(qtrans_getLanguage()=='en'): ?> <li class="liguaattiva">eng</li> <li><a href="<?php echo qtrans_convertURL(get_permalink(), 'it'); ?>" >ita</a></li> <?php endif; ?>
How to solve this without open the last post or come back at the home page, but only switching language in the same page?
-
brasofilo almost 11 yearsI don't get it. Can you write down the exact steps? F.ex.: 1) In Italian home, change language to
en
. 2) Page refreshes in English 3) ??? - - - Or do you mean when you're in Home and swap languages, the site goes to another post? - - - What's the URL generated byqtrans_convertURL(get_permalink(), 'en')
?? - - - - Please, edit the Question to add more details.
-
-
user850010 almost 11 yearsIf you found this answer useful, please take a moment and accept it by clicking on the big checkbox on the left of this answer.
-
markobarna almost 11 yearsSorry but right now I can't vote. "vote up require 15 reputation".