• I want to know how to stylize pages that display specific post content in WordPress. For example, if I have categories Horror and Comedy, how to stylize (change template and css) pages in a way that all posts that are members of category Horror be stylized differently for any post from category Comedy? If a page should display post from Horror category, then give me one page style, if a page should display post from Comedy category, then give me the other page style. Thanks in advance.

Viewing 3 replies - 1 through 3 (of 3 total)
  • possibly with custom category templates;
    https://codex.wordpress.org/Category_Templates

    i.e. create category-horror.php for the Horror category posts; etc.

    Moderator bcworkz

    (@bcworkz)

    Michael is correct (of course) in regard to a listing of posts within a particular category. If that is what you meant, then great! Read no further. It wasn’t too clear to me what you meant. Maybe you meant styling for single post pages or how to style individual posts in a general listing of all posts of any category.

    In those cases, your theme might output a particular category class for the post’s container. For example, twentysixteen (and many other themes) uses the post_class() template tag to output the class attribute for every post’s <article> tag. This function will output a class like “category-horror” for each category term assigned to the post. You can use this class as part of a CSS selector to style the post differently than other posts.

    The category class can be combined with other selectors to style archive lists differently than (though similar to) single post pages. If more than one category is assigned to a post, all of each category specific CSS rules will be applied. In the case of conflicts among rules of the same specificity, the last listed CSS will be the one applied. To avoid unpredictable styling due to multiple categories, the classes output can be managed through the “post_class” filter.

    If you need more control than an article tag class, you can edit the appropriate template to conditionally do different things based on the returned values from wp_get_post_categories().

    Thread Starter natttttan

    (@natttttan)

    Thank you all

    • This reply was modified 7 years, 8 months ago by natttttan.
Viewing 3 replies - 1 through 3 (of 3 total)
  • The topic ‘How to differently style pages that display posts of different category in Wordp’ is closed to new replies.