What template files are used for our custom post type in wordpress?

Template Files for Custom Post Types in WordPress

To create and display custom post types in WordPress, you can use template files. Template files determine how content is displayed on specific pages or post types in your WordPress theme. Here are the template files commonly used for custom post types:

  1. single-{post_type}.php: This template file is used to display a single custom post type. Replace {post_type} with the slug of your custom post type. For example, if your custom post type is "portfolio," the template file would be single-portfolio.php. This file is used when viewing a single post of the custom post type.

  2. archive-{post_type}.php: This template file is used to display the archive page for a custom post type. Replace {post_type} with the slug of your custom post type. For example, if your custom post type is "portfolio," the template file would be archive-portfolio.php. This file is used when viewing a list of posts of the custom post type.

  3. taxonomy-{taxonomy}-{term}.php: This template file is used to display the archive page for a specific term in a custom taxonomy associated with the custom post type. Replace {taxonomy} with the slug of the custom taxonomy and {term} with the slug of the specific term. For example, if your custom taxonomy is "genre" and the term is "action," the template file would be taxonomy-genre-action.php. This file is used when viewing the archive page for a specific term in the custom taxonomy.

  4. taxonomy-{taxonomy}.php: This template file is used to display the archive page for a custom taxonomy associated with the custom post type. Replace {taxonomy} with the slug of the custom taxonomy. For example, if your custom taxonomy is "genre," the template file would be taxonomy-genre.php. This file is used when viewing the archive page for the custom taxonomy.

  5. archive.php: If the specific template files mentioned above are not found, WordPress falls back to the archive.php file. This file is used to display the archive page for any post type, including custom post types.

  6. single.php: If the single-{post_type}.php template file is not found, WordPress falls back to the single.php file. This file is used to display a single post for any post type, including custom post types.

It's important to note that the template files mentioned above should be placed in your WordPress theme folder. You can create these files by duplicating existing template files and modifying them to suit your needs.

[4]