WordPress.org

Ready to get started?Download WordPress

Forums

[resolved] Post templates per category (10 posts)

  1. kanika
    Member
    Posted 1 year ago #

    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)

  2. vtxyzzy
    Member
    Posted 1 year ago #

    See the Codex article on Template Hierarchy, especially the section on 'Category Display'.

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

  3. kanika
    Member
    Posted 1 year ago #

    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.

  4. vtxyzzy
    Member
    Posted 1 year ago #

    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.

  5. kanika
    Member
    Posted 1 year ago #

    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.

  6. vtxyzzy
    Member
    Posted 1 year ago #

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

  7. dragonsjaw
    Member
    Posted 1 year ago #

    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.

  8. kanika
    Member
    Posted 1 year ago #

    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.

  9. kanika
    Member
    Posted 1 year ago #

    I got the solution:

    http://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.

  10. kanika
    Member
    Posted 1 year ago #

Topic Closed

This topic has been closed to new replies.

About this Topic