Like this?
<?php
/*
Plugin Name: Your plugin name
Plugin URI: http://www.domain.com
Description: Description
Author: You obviously
Version: 1.0
*/
/**
* Adds a meta box to the post editing screen
*/
include('meta_box/meta_box.php');
?>
meta_box.php
<?php
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
$page_temp = get_page_template_slug( $post_id );
if ($page_temp == 'template_name.php')
{
function home_custom_meta() {
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
// checks for post/page ID
// I REMOVED THE EDITOR BECAUSE I DIDN'T NEED IT
remove_post_type_support('page', 'editor');
add_meta_box( 'home_meta', __( 'Homepage', 'home-textdomain' ), 'home_meta_callback', 'page' );
add_action('save_post','my_meta_save');
}
add_action( 'add_meta_boxes', 'home_custom_meta' );
/**
* Outputs the content of the meta box
*/
function home_meta_callback( $post ) {
wp_nonce_field( basename( __FILE__ ), 'home_nonce' );
// CONTENT OF THE META BOX GOES HERE
}
/**
* Saves the custom meta input
*/
function home_meta_save( $post_id ) {
// Checks save status
$is_autosave = wp_is_post_autosave( $post_id );
$is_revision = wp_is_post_revision( $post_id );
$is_valid_nonce = ( isset( $_POST[ 'home_nonce' ] ) && wp_verify_nonce( $_POST[ 'home_nonce' ], basename( __FILE__ ) ) ) ? 'true' : 'false';
// Exits script depending on save status
if ( $is_autosave || $is_revision || !$is_valid_nonce ) {
return;
}
// Checks for input and sanitizes/saves if needed
if( isset( $_POST[ 'post_value' ] ) ) {update_post_meta( $post_id, 'post_value', sanitize_text_field( $_POST[ 'post_value' ] ) );}
add_action( 'save_post', 'home_meta_save' );
}
/**
* Adds the meta box stylesheet when appropriate
*/
function home_admin_styles(){global $typenow;
if( $typenow == 'page' ) {wp_enqueue_style( 'meta_box_styles', plugin_dir_url( __FILE__ ) . 'meta-box-styles.css' );}}
add_action( 'admin_print_styles', 'home_admin_styles' );
}
?>