I’m recoding my website with custom post types to be better organized, have a better search experience and being able to hide some pages from other contributors, but I have a little problem.

I’ve set up a post type named Files which contains some files that my contributors should not see. Basically the legal pages, the contact page and so on.

As I had all the pages in the default Pages post type I was able to select a template for each page in the page attributes. Now in my new custom page type, I can only select the order of the page and nothing else. So I have a template for the legal pages and another one for the contact page, which includes all the PHP code. How can I select these templates in my new custom post type?


EDIT

Okay, I’ve understood, that it’s only possible to set a template by setting up a PHP file named single-*(post_type_name)*. But as I said, I’ve two different templates, and more will come very soon, so how can I set these to one or maybe two posts inside that post_type. There must be a possibility, isn’t it? The makers of WordPress will unlikely have us create a new post_type for a single file…

4 Answers
4

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 Reply

Your email address will not be published. Required fields are marked *