Creating and assigning page templates for posts

The process of creating post-specific templates is similar to the process we used earlier. We can just create a template file with the preferred name in the root folder of the theme and add the following comments to the top of the file:

/* Template Name: Featured PostTemplate Post Type: post, product */

In this template, we have to add an additional comment called Template Post Type, with the list of supported post types. Based on our comment, this template will be available for both normal blog posts and the product custom post type. The process of assigning a template to a post is the same as the process we used for pages.

Get WordPress Development Quick Start Guide now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.