WordPress.org

Ready to get started?Download WordPress

Forums

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

  1. lynkei
    Member
    Posted 1 year ago #

    Hello,
    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.
    Thanks

  2. bythegram
    Member
    Posted 1 year 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?

    http://codex.wordpress.org/Function_Reference/post_class

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

    http://codex.wordpress.org/Function_Reference/get_template_part

  3. lynkei
    Member
    Posted 1 year 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?
    Thanks

  4. bythegram
    Member
    Posted 1 year 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?
    http://codex.wordpress.org/Function_Reference/has_category

    ie

    if (has_category('Uncategorized')) :
    //do this
    elseif (has_category('Dining Room')) :
    //do this instead
    endif;
  5. lynkei
    Member
    Posted 1 year ago #

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

    Thanks for your help

  6. lynkei
    Member
    Posted 1 year ago #

    Sorry, meant to mark as resolved.

Topic Closed

This topic has been closed to new replies.

About this Topic

Tags

No tags yet.