Support » Developing with WordPress » Category templates cannot be applied to category pages

  • Resolved eadwig

    (@eadwig)


    Hello everyone

    To display posts with a specific category assigned,
    I followed https://codex.wordpress.org/Category_Templates
    and made sure a specific category had been selected for all of the posts and the category added to the menu.

    However, the category templates could only be applied to them when I clicked on the menu item. The templates would not apply to the preview after clicking the permalink on the Posts Edit screen.

    Please someone help me successfully apply the category template to the posts pages linked through the permalink displayed on the Posts Edit screen.

    Thank you in advance,

    Ead

Viewing 4 replies - 1 through 4 (of 4 total)
  • You need to understand how WordPress decides which template file to use to display a page.
    https://developer.wordpress.org/themes/basics/template-hierarchy/

    Category template files are for displaying a list of posts in that category. A different template file is used when displaying a single post.

    Thanks for the reply.

    I’m aware of the template hierarchy, but the diagram doesn’t help me figure if posts can be displayed differently by category, hence resorting to trying out category-{category-name}.php templates.

    I now understand both category.php and category-{category-name}.php are designed to display category-based archives only. Then, is it possible to apply different category-based pages templates to posts?

    I found this article describing how you can develop a custom single post temple and apply it to target posts:

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

    The method given there lets you create a custom template and assign the template to posts/pages in the post/page edit screen. This did wonders although it doesn’t let you apply the template based on category.

    The same article describes how to apply a custom post template to a specific category, but it’s rather lengthy so I left it at that.

    Moderator Jan Dembowski

    (@jdembowski)

    Forum Moderator and Brute Squad

    Side note: Please do not use short links here. I have expanded your link.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Category templates cannot be applied to category pages’ is closed to new replies.