[resolved] use specified template for all post within specific category (6 posts)

  1. lynkei
    Posted 3 years ago #

    I am wondering if there is a way to set all the posts within a certain post category to use a certain template.

    IOW, I have categories like this:

    • Bedroom
    • Dining Room
    • Living Room
    • Uncategorized

    I would for instance like to set any items within the uncategorized category to use template_01.php and the rest to use template_02.php. I am wondering how this would be done? I am willing to specify it for each individual category if that's what it takes but since I will not be managing this site I don't want to have the user select the template.

  2. bythegram
    Posted 3 years ago #

    Can this be solved by adding a post_class? Meaning is the output completely different between the "templates" or is it just the styling?


    I guess an alternative would be a conditional statement looking for each category and switching "template_part" accordingly.


  3. lynkei
    Posted 3 years ago #

    Thanks "bythegram" for your quick reply.

    Basically here's the deal, I actually have custom fields set up using the "advanced custom fields" plugin. uncategorized items actually have different fields then ones under the other categories.

    So what I'm trying to do is specify a page template for the different categories to display that info in the way I want it to.

    The post_class in that case won't help me and if I'm understanding it right the get_template_part is not actually for templating pages rather loops etc? If so I don't think that solves my issue. Or maybe i'm understanding this incorrectly?

  4. bythegram
    Posted 3 years ago #

    I'm having trouble understanding what you need, do you have an example code of how you are currently displaying your 'info'?

    Could you use conditional checks to change how you display it?


    if (has_category('Uncategorized')) :
    //do this
    elseif (has_category('Dining Room')) :
    //do this instead
  5. lynkei
    Posted 3 years ago #

    Actually, as a matter of fact that has_category function would do it.

    Thanks for your help

  6. lynkei
    Posted 3 years ago #

    Sorry, meant to mark as resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.