I would like to show all articles on my page in two languages while the menu and everything is translated in the language choosen.
<?php
$id=5; $post = get_page($id);
$content = qtrans_use('fr', $post->post_content,false);
echo $content;
?>
This is as far as I got. But I want it to be dynamic with every article.
Thanks for your help!
If you go by that route, you might easily break any other plugin that does stuff with the post content, like custom galleries, excerpt plugins, and such.
I think there is a less destructive way to achieve what you (we) want.
When a post is about to be displayed, the function
qtrans_useCurrentLanguageIfNotFoundShowAvailable
is called by qTranslate, attached as a filter on thethe_content
hook.Since wordpress themes are executed after plugins (I assume you are writing a theme and not a plugin), you can replace that hook with one of your own, outputting the languages you want.
You can do something like this (in your functions.php file)
Note also that there are other hooks you might like to similarly override, like
the_excerpt
orthe_content_rss
.If your blog might not have all the languages for every post (like mine), you might also want to improve your filter, to avoid that the message “Sorry, this entry is only available in Française” in place of the occasional missing english translation:
In this case, don’t be tempted to use
$translated_content
directly, as qTranslate does its job better than us.