3

I have about 100 blog posts and I've been successfully creating 'Page Templates' with ease - and when I create a page I can select the Page Template from the 'Page Attributes' which is all very nice and easy.

I thought the same would be possible for posts...

So I created a post template and saved it as 'single-template-1.php'

Having uploaded the Post Template I notice that there 'Post Attributes' dropdown isn't there so I cant select that template.

Any idea what I could do to fix that?

Thanks!

4

You have to add the following lines at the top of your post template file:

<?php
/*
 * Template Name: Featured Article
 * Template Post Type: post, page, product
 */

 get_header();  ?>

Of course replace "Featured Article" with your desired template name and the list of post types with the post types you want to use the template for.

3
  • I see - is that a new thing - i guess it makes ONE template generic to a formats - is it fair to say that? – henry Nov 23 '17 at 8:48
  • 1
    Yes, it's a pretty recent introduction (came in with Wordpress 4.7), and yes, it is generic in the sense that it can be used for all the post types you specify in the header, included any custom post types you may have. – grazianodev Nov 23 '17 at 9:30
  • You're a lifesaver. Most answers I came across for this said to try toggling the theme or looking at the styles when that single comment missing will cause the template not to display. – Sky Edwards Nov 26 '19 at 23:26
0

If it not works, try to delete * before words

like that

<?php
/*
Template Name: Featured Article
Template Post Type: post, page, product
*/

 get_header();  ?>

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.