• Resolved kanika

    (@kanikawordpresscom)


    Hi,

    I want all my posts in a category to follow a particular template. Which file do I edit?

    eg., the category “Books” should have one Template and the category “General” should have another. I want to be able to customize all of this in code, so I don’t want to do it the plugin way.(even if there is one)

Viewing 9 replies - 1 through 9 (of 9 total)
  • See the Codex article on Template Hierarchy, especially the section on ‘Category Display’.

    Your ‘Books’ template could be named ‘category-books.php’, for example.

    Thread Starter kanika

    (@kanikawordpresscom)

    Thank you for your reply.
    If I am not mistaken, category-{slug}.php dictates how the category-archive page would like, right?

    I want all posts in a category to have a uniform template, different from the posts under another category.

    Also, since I all my posts are of type ‘post’, so I can use only single.php. (i.e. If I have understood the template hierarchy correctly.)
    Thanks,
    Kanika.

    If you are wanting to show posts in different categories on a single screen and have each one styled according to its category, I think you could test for the category while in the loop and use a function to format the display of the post for that category.

    Thread Starter kanika

    (@kanikawordpresscom)

    No, the categories are on different screens.

    Just that the posts of a particular category should have the same template.

    As in, Category A has post1, post2.
    Category B has post3, post4.

    When u click on the permalink of any of these, post1 and post2 should have template1. Post3 and Post4 should have template2.

    Will I have to create custom post_types for this? Can’t do something with categories? Any ideas?

    Thanks,
    Kanika.

    How do you link to the different screens? That will determine what you need to do to use different templates.

    Isn’t this what post formats are for? I think giving the formats actual names wasn’t the best idea, as most are not styled in any way.
    I simply pick one and set the style for how I want the post to appear (ex. all posts in the facebook category.. are styled to look like fb posts). I just have to remember what each format is equal to:
    status = facebook for example.

    I am not doing it by category, but I see no reason that you can’t do it that way, just remember one more thing to tick when making your post.

    Thread Starter kanika

    (@kanikawordpresscom)

    I guess we are all talking on a different plane from each other. If I happen to find a soln, I’ll post it here.

    Thread Starter kanika

    (@kanikawordpresscom)

    I got the solution:

    https://www.wpbeginner.com/wp-themes/create-custom-single-post-templates-for-specific-posts-or-sections-in-wordpress/

    The section:
    Custom Single Post Templates for Specific Category

    deals with this soln.
    The rest of the page is good also.

    Thanks,
    Kanika.

    Thread Starter kanika

    (@kanikawordpresscom)

Viewing 9 replies - 1 through 9 (of 9 total)
  • The topic ‘Post templates per category’ is closed to new replies.