Title: Multiple single.php for the same post
Last modified: August 31, 2016

---

# Multiple single.php for the same post

 *  Resolved [edelcambre](https://wordpress.org/support/users/edelcambre/)
 * (@edelcambre)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/)
 * Hello,
 * I am starting a project where I would need different single.php files for the
   same post, depending on the category. I found some answers based on if(in_category())
   but in my case one post may belong to different categories and be displayed in
   different ways. In fact I’m not sure if categories are what I should use here…
 * So, what I need is to display one post in 2 different ways, in 2 differents URL,
   like this
    [http://www.mysite.com/my-first-category/my-first-post/](http://www.mysite.com/my-first-category/my-first-post/)
   > template 1 [http://www.mysite.com/my-second-category/my-first-post/](http://www.mysite.com/my-second-category/my-first-post/)
   > template 2
 * Any idead how I could do this ?
    Thanks very much in advance! Etienne

Viewing 11 replies - 1 through 11 (of 11 total)

 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258106)
 * Hi edelcambre. You should be able to accomplish this using page templates. There
   are a number of resources available that discuss creating and using page templates.
   Here are a couple of pages from the WP Theme Handbook:
 * [https://developer.wordpress.org/themes/basics/template-hierarchy/](https://developer.wordpress.org/themes/basics/template-hierarchy/)
 * [https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/](https://developer.wordpress.org/themes/template-files-section/page-template-files/page-templates/)
 * Also check [this Google search](https://www.google.com/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#q=wordpress+page+template).
 *  Thread Starter [edelcambre](https://wordpress.org/support/users/edelcambre/)
 * (@edelcambre)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258124)
 * Thanks bdbrown for your answer! Though, I am not sure to understand, are you 
   saying my custom posts should not be displayed as custom posts of a category,
   but within a page ?
 * My first need is actually to get both URL to display something :
    [http://www.mysite.com/my-first-category/my-first-custom-post/](http://www.mysite.com/my-first-category/my-first-custom-post/)
   [http://www.mysite.com/my-second-category/my-first-custom-post/](http://www.mysite.com/my-second-category/my-first-custom-post/)
   So far with permalinks I can only get one to exist…
 * Any other clue ?
 * Thanks again
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258133)
 * This might help clarify it:
    [https://wordpress.org/support/topic/using-a-different-template-for-posts-within-a-specific-category](https://wordpress.org/support/topic/using-a-different-template-for-posts-within-a-specific-category)
 *  Thread Starter [edelcambre](https://wordpress.org/support/users/edelcambre/)
 * (@edelcambre)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258194)
 * Thanks again. I think maybe I did not expose my problem very well. In fact my
   main problem may be a URL problem. Once I can get to exist both of those URL 
   I think it will be easy to have separate templates.
 * In the link you gave me, it has the conditions if(has_term(1)) and if(has_term(
   2)), but my custom post will have both terms, and I want it to be displayed in
   two ways, with both URL, for instance :
    mysite.com/term-1/my-post > template
   single-term1-custom-post.php mysite.com/term-2/my-post > templace single-term2-
   custom-post.php
 * To be more specific, my site is a catalogue of movies. The site is separated 
   in two parts : [http://www.mysite.com/france](http://www.mysite.com/france) and
   [http://www.mysite.com/international](http://www.mysite.com/international). I
   thought france and international could be 2 categories. The 2 front pages would
   be the category-france.php and category-international.php displaying some stuff
   and the movies of the category, with links to post page displayed differently
   depending on the active category.
 * Is there a way to achieve that ?
    Thank again for help,
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258264)
 * OK, I think I have it. You have a post about a movie and it could be assigned
   both the “France” and “International” categories. Depending on which category
   archive page the user is visiting, when they click the link for that movie post,
   you want to display the post content differently based on the caategory page 
   the user was on. Is that it?
 * > The 2 front pages
 * Not sure if you mean 2 category pages? Your site would have only one front/home
   page.
 *  Thread Starter [edelcambre](https://wordpress.org/support/users/edelcambre/)
 * (@edelcambre)
 * [10 years, 2 months ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258269)
 * Yes, that’s exactly it! Regarding the front pages yes I mean the category pages,
   they are kind of front page of each two parts of the website.
 * As for the permalinks, I found some elements [on another forum](http://wordpress.stackexchange.com/questions/196063/how-to-use-two-permalinks-for-one-custom-post-type/223308#223308)
   and could achieve something, but not completely, I explained it [in that thread](http://wordpress.stackexchange.com/questions/223363/how-to-use-two-permalinks-for-one-custom-post-type-based-on-categories)…
 * Thanks again for your time!
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258295)
 * I have some notes somewhere but can’t locate them at the moment. Basically what
   you’d do is set a query argument or query string parameter in the url that’s 
   used to load the single post. In the single post file you would take out the 
   content code and use that to create two new content files, one for France and
   one for International, and change those layouts however you want. Then, in the
   single post file where previously you had the content, you use a php “if” statement
   to check the query parameter or url query string and pull in the related content
   file. Does that make sense?
 * Here are a couple of references that might help:
 * [http://stackoverflow.com/questions/4586835/how-to-pass-extra-variables-in-url-with-wordpress](http://stackoverflow.com/questions/4586835/how-to-pass-extra-variables-in-url-with-wordpress)
 * [http://www.rlmseo.com/blog/passing-get-query-string-parameters-in-wordpress-url/](http://www.rlmseo.com/blog/passing-get-query-string-parameters-in-wordpress-url/)
 * [https://codex.wordpress.org/Function_Reference/get_query_var](https://codex.wordpress.org/Function_Reference/get_query_var)
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258296)
 * [Here’s a Google search](https://www.google.com/search?q=Different+single+post+template+per+category+wordpress&rlz=1C1NNVC_enUS491US548&oq=Different+single+post+template+per+category+wordpress&aqs=chrome..69i57j69i60&sourceid=chrome&ie=UTF-8)
   that might have some relevant results.
 *  Thread Starter [edelcambre](https://wordpress.org/support/users/edelcambre/)
 * (@edelcambre)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258354)
 * Hello,
 * Thanks. I think that is what I do, passing an argument, with my query_vars is_france,
   is_international … The issue I have I think, is with my url_rewrite, which works
   with articles, but not with custom post types… I think with that code I am close
   to the solution, do you have a clue how I can get it to work with custom post
   types ?
 *     ```
       function wpd_query_var( $query_vars ) {
           $query_vars[] = 'is_international';
           $query_vars[] = 'is_france';
           $query_vars[] = 'is_projections_dvd';
           return $query_vars;
       }
       add_filter('query_vars', 'wpd_query_var' , 10, 1 );
   
       function wpd_post_rewrite(){
           add_rewrite_rule(
               'international/([^/]+)/?$',
               'index.php?name=$matches[1]&is_international=1',
               'top'
           );
           add_rewrite_rule(
               'france/([^/]+)/?$',
               'index.php?name=$matches[1]&is_france=1',
               'top'
           );
           add_rewrite_rule(
               'projections_dvd/([^/]+)/?$',
               'index.php?name=$matches[1]&is_projections_dvd=1',
               'top'
           );
       }
       add_action( 'init', 'wpd_post_rewrite' );
   
       function wpd_abstract_template( $single_template ){
           global $wp_query;
           //print_r($wp_query);
   
           if ( isset( $wp_query->query_vars['is_international'] ) ) {
             if(in_category('international')) {
               return locate_template( 'film_international_template.php', false ) ;
             } else {
               return locate_template( '404.php', false ) ;
             }
           } 
   
           if ( isset( $wp_query->query_vars['is_france'] ) ) {
             if(in_category('france')) {
               return locate_template( 'film_france_template.php', false ) ;
             } else {
               return locate_template( '404.php', false ) ;
             }
           } 
   
           if ( isset( $wp_query->query_vars['is_projections_dvd'] ) ) {
             if(in_category('projections_dvd')) {
               return locate_template( 'film_projections_dvd_template.php', false ) ;
             } else {
               return locate_template( '404.php', false ) ;
             }
           } 
   
           return locate_template( 'single.php', false ) ; 
   
       }
       add_filter( 'single_template', 'wpd_abstract_template' );
       ```
   
 *  [bdbrown](https://wordpress.org/support/users/bdbrown/)
 * (@bdbrown)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258386)
 * Try using the post_type parameter for the query.
 * [https://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters](https://codex.wordpress.org/Class_Reference/WP_Query#Type_Parameters)
 * [http://stackoverflow.com/questions/27422021/getting-only-custom-post-types-posts-with-wp-query](http://stackoverflow.com/questions/27422021/getting-only-custom-post-types-posts-with-wp-query)
 *  Thread Starter [edelcambre](https://wordpress.org/support/users/edelcambre/)
 * (@edelcambre)
 * [10 years, 1 month ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258418)
 * Thank you very much, I could endly achieve it with this code for the url_rewrite!
   
   Thanks again for your time
 *     ```
       add_rewrite_rule(
               'france/([^/]+)/?$',
               'index.php?name=$matches[1]&post_type=film&categorie=france',
               'top'
       );
       ```
   

Viewing 11 replies - 1 through 11 (of 11 total)

The topic ‘Multiple single.php for the same post’ is closed to new replies.

## Tags

 * [category](https://wordpress.org/support/topic-tag/category/)
 * [post](https://wordpress.org/support/topic-tag/post/)
 * [single.php](https://wordpress.org/support/topic-tag/single-php/)
 * [template](https://wordpress.org/support/topic-tag/template/)

 * In: [Fixing WordPress](https://wordpress.org/support/forum/how-to-and-troubleshooting/)
 * 11 replies
 * 2 participants
 * Last reply from: [edelcambre](https://wordpress.org/support/users/edelcambre/)
 * Last activity: [10 years, 1 month ago](https://wordpress.org/support/topic/multiple-singlephp-for-the-same-post/#post-7258418)
 * Status: resolved

## Topics

### Topics with no replies

### Non-support topics

### Resolved topics

### Unresolved topics

### All topics
