Add a Template to a custom post type

From what I understand, you’ve got two options.

Option 1: Dynamic Solution Create categories for your custom post type – each category is going to have its own template.

You then create a single template that splits off based on category. Meaning you use the general header and footer in your single-postypename.php and anything else that you want to apply to both templates, but in the meat of it, you then create some php logic for “if category x, use content y template (or partial, I like partials)” and “if category z, use content z template (or partial)”. I assume that if you’re working in templates you’re okay with the code for that, but if not just comment and I can put together an example.

Option 2: Static Solution Each post inside your custom post type gets it’s own template.

You need the single-posttypename.php as your default, but then you can create single-postypename-postslug.php and presto, you have a custom template for that specific post that you can mess around in. As long as your slugs match, it’ll just know what to do.

Option 2 Example:

single-file.php (as your default template)

single-file-legaldocument2.php (as a custom template for yourdomain.ca/file/legaldocument2 )

Leave a Comment