Support » Themes and Templates » Multiple templates for single archive page

  • What is the simplest way to have two (or more) different views of the same page?

    For example, I have a category called ‘events’. By default, when someone goes to the archive page for an event, it will display with the appropriate template defined by the template hierarchy.

    However, I would also like to be able to display an event with a different template (specifically, a lite version of the page used by an announcements mailing list program, or could also be a lite version for viewing on a mobile device).

    What’s the easiest way to achieve this?



Viewing 6 replies - 1 through 6 (of 6 total)
  • Thanks Moshu. Unless I am misreading the info and comments for that plugin, that looks like a great way for assigning a template to a category, however if a post has multiple categories it will display the template based one of those categories, but not allow me to select which template to use.

    Or did I misunderstand how that plugin works?

    Same thing here. A given post in multiple categories will only display using a single template…


    I can’t get the branching single.php to a different single page template beyond the first category specified for a single post.

    But this seems to be able to detect the current category, and return the correct content based on the posts CURRENT category.

    <?php $catname = 0 ;
     $catname = get_query_var('cat');
               if ( $catname =='21') { ?>
    Category 21
    <?php } elseif ( $catname == '19' )  { ?>
    Category 19
    <?php } else  { ?>
    Category Other
    <?php } ?>

    Does anyone have any improvements/corrections I can make to my PHP? It works… but is there a more correct way to do the code?

    This is an ugly hack, but it worked for me. This allows me to select an alternate template (called email) if I add a parameter to the end of a post URL, eg

    To use, create a file called email-theme.php and put it in the WP plugins folder. The file should contain:-

    Plugin Name: Email Theme
    function em_get_template($template) {
            if (!empty($_GET["email"])) {
                    return "email";
            } else {
                    return "mytemplate"; //or whatever my primary template is
    function em_get_stylesheet($stylesheet) {
            if (!empty($_GET["email"])) {
                    return "mytemplate";
            } else {
                    return "mandigo"; //or whatever my primary template is
    add_filter('template', 'em_get_template');
    add_filter('stylesheet', 'em_get_stylesheet');

    I have no doubt this could be improved upon, for example to allow setting of an arbitary number of templates. I haven’t tested at all other than one specific WP installation, but it does the trick for me.

Viewing 6 replies - 1 through 6 (of 6 total)
  • The topic ‘Multiple templates for single archive page’ is closed to new replies.