2

I have a custom post type called funerals and a page the lists all the posts part of that custom post type. To display a single page I create a file called single-funerals.php and that all works well. But, now I need to have another single post page that only displays a video for a funeral. How would I set that up and link to it from the main page that lists all the posts?

4

As I answered here, since WordPress 4.7 Post-Type-Templates are enabled in the WordPress core.

That means that you can create multiple templates for the single post-type view. You create these templates like you would create a normal page template. But you need to add a little more code to these templates:

/*
Template Name: Funerals Video Template 
Template Post Type: post, funerals 
*/

So you will need to copy your single-funerals.php file, rename it, add some code like the above to the top of the file.

After this, you should see a template select box on the post and funerals edit-screen. (because I specified these 2 post-types with Template Post Type: post, funerals)

Read more about post-type-templates here.

  • Thanks for this. I didn't know this existed. This should the accepted answer. – Beee Feb 17 '18 at 14:22
0

You could turn the single-funerals.php code into a 'page template', then use that template when you create the page.

Read about page templates here: https://developer.wordpress.org/themes/template-files-section/page-templates/

  • I'm not understanding your response.. – MF1 Feb 2 '17 at 3:53
0

you can create Post Type Templates It's default WordPress directories file. For More information:

https://codex.wordpress.org/Post_Type_Templates

https://developer.wordpress.org/themes/template-files-section/custom-post-type-template-files/

single-{post_type}.php create this file where your single.php file

single-{post_type}.php

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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