Custom Post Meta Boxes

add_action(“admin_init”, “admin_init”);

function admin_init(){

add_meta_box(“Status”, “Status”, “status”, “Custom post type resister name”, “side”, “low”);
add_meta_box(“Post Tag”, “Post Tag”, “post_tag”, “submit_makeover”, “side”, “low”);
add_meta_box(“ ”, “ ”, “allimage”, “submit_makeover”, “normal”, “high”);
}

function allimage(){
global $post;
$qry=”select * from wp_image where post_id=’”.$post->ID.”‘” ;
$result=mysql_query($qry);
?>
<p><label>All Image:</label><br />
<table style=”width:500px;” >
<tr>
<?php
while($row=mysql_fetch_object($result))
{
?>
<td><img style=”border:4px solid #ccc; border-radius:8px;” src=”<?php echo $row->url; ?>” width=”200″ height=”190″/></td>
<?php } ?>
</tr>
</table>
</p>
<?php
}

function post_tag(){
global $post;
$custom = get_post_custom($post->ID);
$posttag = $custom[“post_tag”][0];

?>
<p><label>Post Tag:</label><br />
<input type=”text” name=”post_tag” value=”<?php echo $posttag; ?>”>
</p>
<?php
}

function status(){
global $post;
$custom = get_post_custom($post->ID);
$status = $custom[“status”][0];

?>
<p><label>Status:</label><br />
<select name=”status” style=”width:100px;height:25px;”>
<option value=””>Select Satus</option>
<option value=”approved” <?php if($status==’approved’){ echo “selected=selected”; } ?>>Approved</option>
<option value=”unapproved”  <?php if($status==’unapproved’){ echo “selected=selected”; } ?>>UnApproved</option>
</select>
</p>
<?php
}

add_action(“manage_posts_custom_column”,  “submit_makeover_custom_columns”);
add_filter(“manage_edit-submit_makeover_columns”, “submit_makeover_edit_columns”);

function submit_makeover_edit_columns($columns){
$columns = array(
“cb” => “<input type=\”checkbox\” />”,
“title” => “Name”,
“email” => “<b>Email</b>”,
“status” => “<b>Status</b>”,
“image” => “<b>Image</b>”,

);

return $columns;
}
function submit_makeover_custom_columns($column){
global $post;
$custom = get_post_custom($post->ID);
$custom_meta = get_post_custom($post->ID);
$thumb = $custom_meta[‘image’][0];

switch ($column) {
case “email”:
echo $custom[“email”][0];
break;
case “status”:
if($custom[“status”][0]==’approved’)
{
?>
<p style=”color:green;”><?php echo $custom[“status”][0]; ?></p>
<?php }
else
{?>
<p style=”color:red;”><?php echo $custom[“status”][0]; ?></p>
<?php }
break;
case “image”: ?>

<img src=”<?php echo($thumb); ?>” alt=”<?php echo($title); ?>” width=”70″ height=”60″ id=”galleryPic2″ />
<?php
break;

}
}

add_action(‘save_post’, ‘save_details’);

function save_details(){
global $post;
update_post_meta($post->ID, “status”, $_POST[“status”]);
update_post_meta($post->ID, “post_tag”, $_POST[“post_tag”]);

}

function sgwc_metaboxes( $meta_boxes ) {
$prefix = ‘sm_’; // Prefix for all fields

$meta_boxes[] = array(
‘id’ => ‘header_image_widget’,
‘title’ => ‘Header Images’,
‘pages’ => array(‘submit_makeover’), // post type
‘context’ => ‘normal’,
‘priority’ => ‘high’,
‘show_names’ => true, // Show field names on the left
‘fields’ => array(

array(
‘name’ => ‘Upload video’,
‘desc’ => ‘(Optimal size 519 px by 346 px)’,
‘id’ =>’image’,
‘type’ => ‘file’,
‘save_id’ => false, // save ID using true
‘allow’ => array( ‘url’, ‘attachment’ ) // limit to just attachments with array( ‘attachment’ ),
),
array(
‘name’ => ‘Name’,
//’desc’ => ‘field description (optional)’,
‘id’   =>’names’,
‘width’ => ’300′,
‘type’ => ‘text’

),

array(
‘name’ => ‘Email’,
//’desc’ => ‘field description (optional)’,
‘id’   =>’email’,
‘width’ => ’300px’,
‘type’ => ‘text’

)
)
);

return $meta_boxes;
}
add_filter( ‘cmb_meta_boxes’, ‘sgwc_metaboxes’ );

// Initialize the metabox class
add_action( ‘init’, ‘sgwc_initialize_metaboxes’, 9999 );

function sgwc_initialize_metaboxes() {
if ( !class_exists( ‘cmb_Meta_Box’ ) ) {
require_once( ‘lib/cmb/init.php’ );
}
}

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s