Support » Fixing WordPress » Divorce templates from categories

  • Is there a (best) way to divorce templates from categories?

    When I blog about upcoming movies, I want all posts to show in my Movies category page, but I want a slightly different template for those showing at Theater A and Theater B.

    Should I:
    – install an “execute PHP” plug-in so I can set a PHP variable in the post and have the template conditionalize on that (include Theater A info or Theater B info in the template)
    – make Movies a category and “Theater A” and “Theater B” subcategories, assign a different template to each but have the main Movies page work off the uber-category
    – another solution?

Viewing 5 replies - 1 through 5 (of 5 total)
  • If you mean ‘slightly different’ when viewing an individual movie, your best solution is #2, or the equivalent with a custom field, and then have your single.php wrap a custom CSS class around the post depending on the theater (cat or custom field), and then you can do everything from CSS overrides.

    The same can be done in a Movies cat/archive template, if you want each sub-post on the page to be slightly differently styled — just wrap the post output with a div classed depending upon the theater. Then do the ‘heavy lifting’ in CSS. That way it’ll naturally expand in the CSS file as you add theaters, rather than continually editing the php code. 😉


    Actually, I’m realizing that my real question is quite simple:

    Can you assign a different template for each category of single post?

    The issue is that you could have multiple categories per post. Which does it then use?

    The logic, at that point, is easier to embed into one universal single.php, with a simple test, output a special wrappering DIV with an id or class name that makes sense, and then, again, everything else is completely controlled in CSS. You’d do the CSS ‘piece’ even if you had multiple template php files… this just ‘simplifies the logic branching…’.


    Thanks, much appreciated!

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘Divorce templates from categories’ is closed to new replies.