WordPress.org

Ready to get started?Download WordPress

Forums

Divorce templates from categories (6 posts)

  1. timz10000
    Member
    Posted 8 years ago #

    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?

  2. davidchait
    Member
    Posted 8 years ago #

    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. ;)

    -d

  3. timz10000
    Member
    Posted 8 years ago #

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

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

  4. Chris_K
    Member
    Posted 8 years ago #

  5. davidchait
    Member
    Posted 8 years ago #

    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...'.

    -d

  6. timz10000
    Member
    Posted 8 years ago #

    Thanks, much appreciated!

Topic Closed

This topic has been closed to new replies.

About this Topic