<?php
// --- METABOX CREATE --- //
//add_action('admin_init', 'page_spec_meta');
add_action( 'load-post.php', 'page_spec_meta' );
function page_spec_meta(){
$post_id = (isset($_GET['post'])) ? $_GET['post'] : $_POST['post_ID'] ;
$template_file = get_post_meta($post_id,'_wp_page_template',TRUE);
if ($template_file == 'talenten.php')
{
add_meta_box("career-meta", "Career", "career_meta", "page", "normal", "high");
add_meta_box("business-meta", "Business", "business_meta", "page", "normal", "high");
add_meta_box("inspired-meta", "inspired", "inspired_meta", "page", "normal", "high");
add_meta_box("network-meta", "Network", "network_meta", "page", "normal", "high");
add_meta_box("future-meta", "Future", "future_meta", "page", "normal", "high");
add_action( 'save_post', 'save_custom_meta');
}
if ($template_file == 'bedrijven.php')
{
add_meta_box("unique-meta", "Unique", "unique_meta", "page", "normal", "high");
add_meta_box("providing-meta", "Providing", "providing_meta", "page", "normal", "high");
add_meta_box("inspired-meta", "inspired", "inspired_meta", "page", "normal", "high");
add_meta_box("network-meta", "Network", "network_meta", "page", "normal", "high");
add_meta_box("future-meta", "Future", "future_meta", "page", "normal", "high");
add_action( 'save_post', 'save_custom_meta');
}
}
// --- METABOX: CAREER ... CONTENTS --- //
function career_meta($object){
$career1 = get_post_meta( $object->ID, 'career1', true );
$career2 = get_post_meta( $object->ID, 'career2', true );
$career3 = get_post_meta( $object->ID, 'career3', true );
?>
<label for="career1">Subtitel</label><input type="text" class="widefat" id="career1" name="career1" value="<?php echo $career1; ?>" />
<label for="career2">Textveld Links</label>
<textarea id="career2" name="career2"><?php echo $career2; ?></textarea>
<label for="career3">Textveld Rechts</label>
<textarea id="career3" name="career3"><?php echo $career3; ?></textarea>
<input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
<?php }
// --- METABOX: BUSINESS ... CONTENTS --- //
function business_meta($object){
$business1 = get_post_meta( $object->ID, 'business1', true );
$business2 = get_post_meta( $object->ID, 'business2', true );
$business3 = get_post_meta( $object->ID, 'business3', true );
$business4 = get_post_meta( $object->ID, 'business4', true );
$business5 = get_post_meta( $object->ID, 'business5', true );
$business6 = get_post_meta( $object->ID, 'business6', true );
?>
<label for="business1">Subtitel</label><input type="text" class="widefat" id="business1" name="business1" value="<?php echo $business1; ?>" />
<label for="business2">Textveld Links</label>
<textarea id="business2" name="business2"><?php echo $business2; ?></textarea>
<label for="business3">Textveld Rechts</label>
<textarea id="business3" name="business3"><?php echo $business3; ?></textarea>
<label for="business4">Textveld Links</label>
<textarea id="business4" name="business4"><?php echo $business4; ?></textarea>
<label for="business5">Textveld Rechts</label>
<textarea id="business5" name="business5"><?php echo $business5; ?></textarea>
<label for="business6">Textveld Links</label>
<textarea id="business6" name="business6"><?php echo $business6; ?></textarea>
<input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
<?php }
// --- METABOX: INSPIRED ... CONTENTS --- //
function inspired_meta($object){
$inspired1 = get_post_meta( $object->ID, 'inspired1', true );
$inspired2 = get_post_meta( $object->ID, 'inspired2', true );
?>
<label for="inspired1">Subtitel</label><input type="text" class="widefat" id="inspired1" name="inspired1" value="<?php echo $inspired1; ?>" />
<label for="inspired2">Textveld Links</label>
<textarea id="inspired2" name="inspired2"><?php echo $inspired2; ?></textarea>
<input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
<?php }
// --- METABOX: NETWORK ... CONTENTS --- //
function network_meta($object){
$network1 = get_post_meta( $object->ID, 'network1', true );
$network2 = get_post_meta( $object->ID, 'network2', true );
?>
<label for="network1">Subtitel</label><input type="text" class="widefat" id="network1" name="network1" value="<?php echo $network1; ?>" />
<label for="network2">Textveld Links</label>
<textarea id="network2" name="network2"><?php echo $network2; ?></textarea>
<input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
<?php }
// --- METABOX: FUTURE ... CONTENTS --- //
function future_meta($object){
$future1 = get_post_meta( $object->ID, 'future1', true );
$future2 = get_post_meta( $object->ID, 'future2', true );
?>
<label for="future1">Subtitel</label><input type="text" class="widefat" id="future1" name="future1" value="<?php echo $future1; ?>" />
<label for="future2">Textveld Links</label>
<textarea id="future2" name="future2"><?php echo $future2; ?></textarea>
<input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
<?php }
// --- METABOX: UNIQUE ... CONTENTS --- //
function unique_meta($object){
$unique1 = get_post_meta( $object->ID, 'unique1', true );
$unique2 = get_post_meta( $object->ID, 'unique2', true );
?>
<label for="unique1">Subtitel</label><input type="text" class="widefat" id="unique1" name="unique1" value="<?php echo $unique1; ?>" />
<label for="unique2">Textveld Links</label>
<textarea id="unique2" name="unique2"><?php echo $unique2; ?></textarea>
<input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
<?php }
// --- METABOX: PROVIDING ... CONTENTS --- //
function providing_meta($object){
$providing1 = get_post_meta( $object->ID, 'providing1', true );
$providing2 = get_post_meta( $object->ID, 'providing2', true );
$providing3 = get_post_meta( $object->ID, 'providing3', true );
$providing4 = get_post_meta( $object->ID, 'providing4', true );
?>
<label for="providing1">Subtitel</label><input type="text" class="widefat" id="providing1" name="providing1" value="<?php echo $providing1; ?>" />
<label for="providing2">Textveld Links</label>
<textarea id="providing2" name="providing2"><?php echo $providing2; ?></textarea>
<label for="providing3">Textveld Rechts</label>
<textarea id="providing3" name="providing3"><?php echo $providing3; ?></textarea>
<label for="providing4">Textveld Links</label>
<textarea id="providing4" name="providing4"><?php echo $providing4; ?></textarea>
<input type="hidden" name="my_meta_box_nonce" value="<?php echo wp_create_nonce('my_meta_box') ?>" />
<?php }
// Save the Data
function save_custom_meta($post_id) {
$custom_meta_fields = array(
'career1','career2','career3',
'business1','business2','business3','business4','business5','business6',
'inspired1','inspired2',
'network1','network2',
'future1','future2',
'unique1','unique2',
'providing1','providing2','providing3','providing4'
);
//echo $_POST['my_meta_box_nonce'];
// verify nonce
if (!wp_verify_nonce($_POST['my_meta_box_nonce'], 'my_meta_box'))
return $post_id;
// check autosave
if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE)
return $post_id;
// check permissions
if ('page' == $_POST['post_type']) {
if (!current_user_can('edit_page', $post_id))
return $post_id;
} elseif (!current_user_can('edit_post', $post_id)) {
return $post_id;
}
// loop through fields and save the data
foreach ($custom_meta_fields as $field) {
if(isset($_POST[$field])) {
$old = get_post_meta($post_id, $field, true);
$new = $_POST[$field];
if ($new && $new != $old) {
update_post_meta($post_id, $field, $new);
} elseif ('' == $new && $old) {
delete_post_meta($post_id, $field, $old);
}
}
} // end foreach
}
?>