I’m using the Options Framework Theme to put together my options page and would just like to know how would I set up/call the Default Template – for whichever one the user has selected.
For example, on my Theme Options page, you can choose from the following:
- Full Page
- Side Bar Left
- Side Bar Right
Which looks something like this:
Once the user has selected one of these options, when they go to create a New Page, in the Page Attributes > Template drop-down menu, the “Default Template” should be the one that they chose from before…
In my options.php
file:
$options[] = array(
'name' => "Default Template",
'desc' => "The default layout when a new page is created.",
'id' => "layout_options",
'std' => "2c-r-fixed",
'type' => "images",
'options' => array(
'1col-fixed' => $imagepath . '1col.png',
'2c-l-fixed' => $imagepath . '2cl.png',
'2c-r-fixed' => $imagepath . '2cr.png')
);
To call the output:
<?php echo of_get_option('layout_options', 'no entry' ); ?>
Where/what would I need to paste in throughout my theme files to grab the users selection and point it towards the Default Template, as currently it may only be saving the selected image?
The better, cleaner solution would be not to use custom page templates to define page layouts*, but rather to use custom post meta to define page layouts.
To implement:
_page_layout
custom post meta for Page Layout, that includes a “Default Layout” option, as well as all possible layout options used in the above Theme Optionbody_class
filter to output alayout-$layout
class to the HTML<body>
tag, via thebody_class()
template tag, where$layout
is defined as so:'default' == '_page_layout'
, use the Theme Option value'$layout' == '_page_layout'
, use$layout
Proof-of-concept code from Oenology follows (note: modified from original, since I apply custom post meta for layouts for static pages, single blog posts, and archive index pages):
Adding Meta Boxes
Determining Current Page Layout
Filtering Body Class
*Custom page templates really weren’t intended for defining layouts, but rather for defining custom page content.