This is also on my wish list. I want to include features in my framework to recognize custom post types automatically and provide layout options. As of now you must add the code for the new layouts manually, but it’s not difficult. Besides just recognizing the post types, I also hope to build out a way that the function which is called to set the page “context” to determine the theme’s template-[context].php
file can have an additional parameter which will generate a custom layout field in the admin as well.
I don’t know how far out these features are because right now I’m spending most of my time focusing on the actual theme code and cannot dedicate much to the underlying framework. I do try to make small updates for the areas I’m working on as I do theme updates but these are minimal.
As for creating the fields manually. There are a couple of changes you must make, below are the steps. You may not need to do step 1 and 2 if you already have a file with the required theme layout function and template file.
1. Open the file archive-[post-type].php
or whatever the name is of your custom post type target page. Copy the content out of the file and save it to a new file named “template-[context].php
” where the “[context]” is the description of the output type. If you are going to use an existing templage file like “template-blog.php” or “template-page.php” you do not need to create the new file.
2. Copy the default layout function to your archive-[post-type].php
file and update the function parameter for “context” to be the same as the file template-[context].php
.
create_page_layout('context');
3. Open the file “framework/layout-settings/admin-options-defaults.php
” and duplicate the code for the default “Page” layout. You’ll find it around line 100. It will look like this:
// Pages
$select = $select_layout;
$comment = __('The default layout to use for new pages.', THEME_NAME);
$comment = $layout_admin->format_comment($comment);
$row = array(__('Pages', THEME_NAME), $layout_admin->settings_select('layout,page', $select) . $comment);
$layout_admin->setting_row($row);
4. Change the reference for the context (the 5th line in the block of code you just duplicated). I’ve demonstrated the change to that line in the code below.
$row = array(__('Post-type Name', THEME_NAME), $layout_admin->settings_select('layout,context', $select) . $comment);
The “context” must be exactly the same as what you entered for the function in step 2.
5. Open the file “framework/layout-settings/settings-object.php
” and add the new context to the array on line 25 (or near there) :
'layout' => array('header', 'footer', 'default', 'home', 'page', 'post', 'blog', 'category', 'author', 'tag', 'date', 'search', 'error', '[context]' )
(The example above is shortened from the actual code in the file to make it easier to read. Just add your context to the end of the array, the order of the items makes no difference.)
That should do it. Save the files, upload them to your site.