add_action( 'admin_init', 'til_meta_boxes');
function til_meta_boxes() {
add_meta_box('til_pagetemplates_meta', 'Page Template Settings', 'til_pagetemplates_meta', 'page', 'side');
}
//*********** Page Templates Area **************
function til_pagetemplates_meta() {
global $post;
$temp = maybe_unserialize(get_post_meta($post->ID,'til_ptemplate_settings',true));
$fullwidth = isset($temp['fullwidth']) ? $temp['fullwidth'] : '';
$categories = isset($temp['categories']) ? $temp['categories'] : '';
$blog_posts = isset($temp['blog_posts']) ? $temp['blog_posts'] : '';
$portfolio_posts = isset($temp['portfolio_posts']) ? $temp['portfolio_posts'] : '';
$show_title = isset($temp['show_title']) ? $temp['show_title'] : '';
$show_desc = isset($temp['show_desc']) ? $temp['show_desc'] : '';
$map = isset($temp['map']) ? $temp['map'] : '';
$til_calltoaction_lefttext = isset($temp['calltoaction_left']) ? $temp['calltoaction_left'] : '';
$til_calltoaction_righttext = isset($temp['calltoaction_right']) ? $temp['calltoaction_right'] : '';
$til_calltoaction_url = isset($temp['calltoaction_url']) ? $temp['calltoaction_url'] : '';
$til_calltoaction_page = isset($temp['calltoaction_page']) ? $temp['calltoaction_page'] : '';
?>
Here you'll see some page template options(just for the theme specific page templates)
<div style="margin: 15px 0px 15px 0px; display: none" class="contact blog">
<label style="font-weight: bold" for="til_fullwidth">Full width page?</label>
<input type="checkbox" name="til_fullwidth" id="til_fullwidth" value="" <?php checked( $fullwidth ); ?> />
</div>
<div style="margin: 15px 0px 15px 0px; display: none" class="portfolio blog paged_portfolio">
<h4>Select categories to include: </h4>
<?php $cats_array = get_categories('hide_empty=0');
foreach ($cats_array as $cat) {
$checked = '';
if (!empty($categories)) {
if (in_array($cat->cat_ID, $categories)) $checked = "checked=\"checked\"";
} ?>
<label style="padding-bottom: 5px; display: block" for="<?php echo 'cat-' . $cat->cat_ID; ?>">
<input type="checkbox" name="til_categories[]" id="<?php echo 'cat-' . $cat->cat_ID; ?>" value="<?php echo $cat->cat_ID; ?>" <?php echo $checked; ?> />
<?php echo $cat->cat_name; ?>
</label>
<?php } ?>
</div>
<div style="margin: 15px 0px 15px 0px; display: none" class="blog">
<label style="font-weight: bold" for="til_blogposts">Number of blog posts per page:</label>
<input size="2" type="text" name="til_blogposts" id="til_blogposts" value="<?php if($blog_posts == '') echo '6'; else echo $blog_posts;?>" />
</div>
<div style="margin: 15px 0px 15px 0px; display: none" class="calltoaction">
<label style="font-weight: bold" for="til_calltoaction_lefttext">Call to action left text:</label>
<input size="37" type="text" name="til_calltoaction_lefttext" id="til_calltoaction_lefttext" value="<?php if($til_calltoaction_lefttext == '') echo 'Need to make an'; else echo $til_calltoaction_lefttext;?>" />
</div>
<div style="margin: 15px 0px 15px 0px; display: none" class="calltoaction">
<label style="font-weight: bold" for="til_calltoaction_righttext">Call to action right text:</label>
<input size="37" type="text" name="til_calltoaction_righttext" id="til_calltoaction_righttext" value="<?php if($til_calltoaction_righttext == '') echo 'Appointment now'; else echo $til_calltoaction_righttext;?>" />
</div>
<div style="margin: 15px 0px 15px 0px; display: none" class="calltoaction">
<label style="font-weight: bold" for="til_calltoaction_url">Call to action link:</label>
<input size="37" type="text" name="til_calltoaction_url" id="til_calltoaction_url" value="<?php if($til_calltoaction_url == '') echo ''; else echo $til_calltoaction_url;?>" />
</div>
<div style="margin: 15px 0px 15px 0px; display: none" class="calltoaction">
<h4>Select the page to include after the call to action button: </h4>
<?php $pages_array = get_pages('');
foreach ($pages_array as $pg) {
$checked = '';
if (!empty($pages_array)) {
if ($pg->ID == $til_calltoaction_page) $checked = "checked=\"checked\"";
} ?>
<label style="padding-bottom: 5px; display: block" for="<?php echo 'page-' . $pg->ID; ?>">
<input type="radio" name="til_calltoaction_page" id="<?php echo 'page-' . $pg->ID; ?>" value="<?php echo $pg->ID; ?>" <?php echo $checked; ?> />
<?php echo $pg->post_title; ?>
</label>
<?php } ?>
</div>
<div style="margin: 15px 0px 15px 0px; display: none" class="paged_portfolio">
<label style="font-weight: bold" for="til_portfolioposts">Number of portfolio posts per page:</label>
<input size="2" type="text" name="til_portfolioposts" id="til_portfolioposts" value="<?php if($portfolio_posts == '') echo '6'; else echo $portfolio_posts;?>" />
</div>
<div style="margin: 15px 0px 15px 0px; display: none" class="portfolio paged_portfolio">
<label style="font-weight: bold" for="til_showtitle">Show post title in portfolio:</label>
<input type="checkbox" name="til_showtitle" id="til_showtitle" value=""<?php checked( $show_title ); ?> />
</div>
<div style="margin: 15px 0px 15px 0px; display: none" class="portfolio paged_portfolio">
<label style="font-weight: bold" for="til_showdesc">Show post description in portfolio:</label>
<input type="checkbox" name="til_showdesc" id="til_showdesc" value=""<?php checked( $show_desc ); ?> />
</div>
<div style="margin: 15px 0px 15px 0px; display: none" class="contact">
<label style="font-weight: bold" for="til_map">Map url:</label>
<input size="30" type="text" name="til_map" id="til_map" value="<?php echo $map;?>" />
<em>The url from the google maps page, get the url manually from the iframe tag. Check the docs if you're not sure how to do it</em>
</div>
<script type="text/javascript">
jQuery(document).ready(function() {
var page_template = jQuery('select#page_template'),
page_template_div = jQuery('#til_pagetemplates_meta');
page_template.on('change', function() {
page_template_div.find('.inside > div').css('display','none');
var ptval = jQuery(this).val();
if(ptval === "page-template-portfolio-2.php" || ptval === "page-template-portfolio-3.php" || ptval === "page-template-portfolio-4.php" || ptval === "page-template-portfolio-1.php")
jQuery("div.paged_portfolio").show(400);
else
if(ptval === "page-template-portfolio.php")
jQuery("div.portfolio").show(400);
if(ptval === "page-template-contact.php")
jQuery("div.contact").show(400);
else
if(ptval === "page-template-blog.php")
jQuery("div.blog").show(400);
else
if(ptval === "page-template-calltoaction.php")
jQuery("div.calltoaction").show(400);
});
page_template.trigger('change');
});
</script>
<?php
}
add_action('save_post', 'til_save_ptemplate_settings', 10, 2);
function til_save_ptemplate_settings($post_id, $post)
{
// verify if this is an auto save routine.
// If it is our form has not been submitted, so we dont want to do anything
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
return;
// Check permissions
if ( 'page' == $post->post_type )
{
if ( !current_user_can( 'edit_page', $post_id ) )
return;
}
else
{
if ( !current_user_can( 'edit_post', $post_id ) )
return;
}
$temp = array();
$temp['page_template'] = 'page-template-portfolio.php ';
if(isset($_POST['til_fullwidth']))
$temp['fullwidth'] = 1;
else
$temp['fullwidth'] = 0;
if(isset($_POST['til_showtitle']))
$temp['show_title'] = 1;
else
$temp['show_title'] = 0;
if(isset($_POST['til_showdesc']))
$temp['show_desc'] = 1;
else
$temp['show_desc'] = 0;
if(isset($_POST['til_categories']))
{
$temp['categories'] = (array)$_POST['til_categories'];
}
else
$temp['categories'] = '';
if(isset($_POST['til_blogposts']) != '' && is_numeric($_POST['til_blogposts']) )
$temp['blog_posts'] = (int)$_POST['til_blogposts'];
else
$temp['blog_posts'] = 6;
if(isset($_POST['til_portfolioposts']) != '' && is_numeric($_POST['til_portfolioposts']) )
$temp['portfolio_posts'] = (int)$_POST['til_portfolioposts'];
else
$temp['portfolio_posts'] = 6;
if(isset($_POST['til_map']) && $_POST['til_map'] != '')
$temp['map'] = esc_attr($_POST['til_map']);
else
$temp['map'] = '';
if(isset($_POST['til_calltoaction_lefttext']) && $_POST['til_calltoaction_lefttext'] != '')
$temp['calltoaction_left'] = esc_html($_POST['til_calltoaction_lefttext']);
else
$temp['calltoaction_left'] = '';
if(isset($_POST['til_calltoaction_righttext']) && $_POST['til_calltoaction_righttext'] != '')
$temp['calltoaction_right'] = esc_html($_POST['til_calltoaction_righttext']);
else
$temp['calltoaction_right'] = '';
if(isset($_POST['til_calltoaction_url']) && $_POST['til_calltoaction_url'] != '')
$temp['calltoaction_url'] = esc_html($_POST['til_calltoaction_url']);
else
$temp['calltoaction_url'] = '';
if(isset($_POST['til_calltoaction_page']) && is_numeric($_POST['til_calltoaction_page']) )
$temp['calltoaction_page'] = (int)$_POST['til_calltoaction_page'];
else
$temp['calltoaction_page'] = '';
update_post_meta($post_id, 'til_ptemplate_settings', $temp);
}