1

If a user is editing a page, they have the option to choose any page template for that page through the edit screen. Wordpress does not have that option for posts.

I installed the Sparkling theme and noticed that they were able to include layout options for the user to select on the posts edit screen.

How would I be able to do the same thing on my theme? Perhaps someone can guide me in the right direction.

I included a screen shot and circled the options I am trying to add to my theme:

enter image description here

3

3 Answers 3

2

Wordpress provides a template hierarchy which gives you the flexibility to create custom layouts for posts, pages, archives, etc. To create a custom layout for a specific blog post, you would name the template single-{post-type}-{slug}.php

You can find out more about the template hierarchy here

6
  • I thought this feature is only available for page templates? So you mean I can create a new template named single-post-fullwidth.php and it will show up in the posts edit screen? Commented Apr 24, 2016 at 3:24
  • yes of course the example which you mentioned above done same thing
    – Owais Alam
    Commented Apr 24, 2016 at 12:35
  • Here's what I did: I created two templates files and named them single-post-fullwidth.php and single-post-sidebar.php and I also included a php statement in each file to give them each a unique name. <?php Post template name: fullwidth ?> I read about this somewhere else and it seems like that this method requires a plugin but I am trying to accomplish this without the use of a plugin Commented Apr 24, 2016 at 22:23
  • <?php /* Template Name: Template_Name */ ?> give your template name and select it than you can accomplish your goal
    – Owais Alam
    Commented Apr 25, 2016 at 7:25
  • <?php /* Template Name: Template_Name */ ?> this statement only applies to pages though I am referring to the post type Posts Commented Apr 27, 2016 at 5:48
0

You can do this by creating a custom metabox. You can then use the selected value to choose your template part.

eg. if fullwidth is chosen:- get_template_part('template-part/','fullwidth'); where 'template-part/' is a folder and 'fullwidth' is file with .php extension. read more here

There are a lot of online generators to create a metabox if you want to skip the hassle of making one your self. Simply generate and paste the code in functions.php of your theme

check out https://jeremyhixon.com/tool/wordpress-meta-box-generator/

-1

This option is likely added with post_meta. The panel option looks like it was was added with the add_meta_box.

Post meta is a common place to put additional data to posts in WordPress.

Post meta boxes are an easy way to show fields for this options to be displayed.

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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