Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

I have two page templates and Qtranslate installed.

I want to choose one or another depending the language selected.

Can I do something like this ?

if($q_config['lang'] == 'en'){
// load page-template_en.php
}else{
// load page-template_de.php
}

Any idea ?

Thanks!

share|improve this question
add comment

3 Answers

up vote 0 down vote accepted

It is possible using the template_redirect hook.

Looks something like this :

 function language_redirect()
 {
      global $q_config;

      if( $q_config['lang'] == 'en' )
      {
           include( get_template_directory() . '/page-template_en.php' );
           exit;
      }
      else
      {
           include( get_template_directory() . '/page-template_de.php' );
           exit;
      }
 }
 add_action( 'template_redirect', 'language_redirect' );

Code is untested, but should look like that.

See my similar answer HERE for more help.

share|improve this answer
add comment

Finally found it! If I understand your question right, the template is basically saved as metadata that needs to be updated.

update_post_meta( $post_id, '_wp_page_template', 'your_custom_template' );
// or
update_metadata('post_type',  $post_id, '_wp_page_template', 'your_custom_template' );

Source and further info

share|improve this answer
add comment

Should be possible using the template_include hook. Code is untested:

 add_action( 'template_include', 'language_redirect' );

 function language_redirect( $template )
 {
      global $q_config;
      $lang = ( $q_config['lang'] == 'en' ) ? 'en' : 'de';

      $template = str_replace( '.php', '_'.$lang.'.php', $template );
      return $template;
 }
share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.