0

While I was reading template hierarchy.

The single post template file is used to render a single post. WordPress uses the following path:

single-{post-type}-{slug}.php – (Since 4.4) First, WordPress looks for a template for the specific post. For example, if post type is product and the post slug is dmc-12, WordPress would look for single-product-dmc-12.php.

single-{post-type}.php – If the post type is product, WordPress would look for single-product.php.

I am slightly confused the above two in bold face do they differ technically somehow or It is Just the matter of convention while creating Templates for Posts.

6
  • They do not differ technically. If single-{post-type}-{slug}.php does not exist then WordPress will load single-{post-type}.php. If you want the product page for a single product to look different than the other product pages, then you would create single-{post-type}-{slug}.php so that only that one product page is affected Apr 11, 2016 at 18:46
  • Didn't get this part - "If you want the product page for a single product to look different than the other product pages, then you would create single-{post-type}-{slug}.php so that only that one product page is affected" you mean product archive page and product single page?
    – WordCent
    Apr 11, 2016 at 18:51
  • These templates are for product single pages Apr 11, 2016 at 19:15
  • Oh I See you mean to say one will be default and another will be available as an option to choose while creating product pages?
    – WordCent
    Apr 11, 2016 at 19:17
  • No it will not be available as an option. These files exist in your theme directory and the template that loads is determined by the following: If you have a product with slug of dmc-12, then WordPress will first look for a file called single-product-dmc-12.php in the theme directory. If it finds it it will use that template when creating the page. If this file does not exist, then it will look for a file called single-product.php in the theme directory. If that file does not exist, then WordPress will look for a file called single.php in the theme directory. Apr 11, 2016 at 19:25

1 Answer 1

0

They do not differ technically. These files exist in your theme directory and the template that loads is determined by the following: If you have a product with slug of dmc-12, then WordPress will first look for a file called single-product-dmc-12.php in the theme directory. If it finds it it will use that template when creating the page. If this file does not exist, then it will look for a file called single-product.php in the theme directory. If that file does not exist, then WordPress will look for a file called single.php in the theme directory.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.