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.

In Joomla! articles can use multiple templates. I could only put ath the end of url ?template=templatename and article uses the template "templatename".

Is this possible in Wordpress?

share|improve this question
add comment

1 Answer

up vote 2 down vote accepted

Yes it is. But no by default.

But it's pretty easy to do it yourself.

You can do it in 2 ways:

1. In single.php template file

Just add if statement and use get_template_part function to load selected template.

So your single.php file could look like this:

<?php
if ( isset($_GET['template']) ) {
    switch ($_GET['template']) {
        case 'a':
            get_template_part('single-post-template-a');
            break;
        ...        
    }
} else {
    get_template_part('single-post-template-default');
}

2. Using single_template hook.

function get_custom_post_type_template($single_template) {
     global $post;

     if ($post->post_type == 'post' && isset($_GET['template']) ) {
          switch ( $_GET['template'] ) {
               case 'a':
                   return locate_template( array('/single-post-template-a.php') );
                   break;
               ...
          }
     }
     return $single_template;
}
add_filter( 'single_template', 'get_custom_post_type_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.