<script src=”https://cdn.bootcss.com/jquery/1.12.4/jquery.min.js”></script>
<script src=”<? php bloginfo(‘template_directory’); ?>/ images/jquery.imagezoom.min.js”></script>
.box{width:380px;}
.box img{vertical-align:top;border:0;}
.tb-pic a{display:table-cell;text-align:center;vertical-align:middle;}
.tb-pic a img{vertical-align:middle;}
.tb-pic a{*display:block;*font-family:Arial;*line-height:1;}
.tb-thumb{margin:10px 0 0;overflow:hidden;}
.tb-thumb li{background:none repeat scroll 0 0 transparent;float:left;height:42px;margin:0 6px 0 0;overflow:hidden;padding:1px;}
.tb-s310, .tb-s310 a{height:310px;width:380px;}
.tb-s310{max-height:310px;max-width:380px;}
.tb-s310 img{max-height:306px;max-width:376px;}
.tb-s310 a{*font-size:271px;}
.tb-s40 a{*font-size:35px;}
.tb-s40 img{width:40px;height:40px;}
.tb-s40, .tb-s40 a{height:40px;width:40px;}
.tb-booth{border:1px solid #CDCDCD;position:relative;z-index:1;}
.tb-thumb .tb-selected{background:none repeat scroll 0 0 #C30008;height:44px;padding:2px;}
.tb-thumb .tb-selected div{background-color:#FFFFFF;border:medium none;}
.tb-thumb li div{border:1px solid #CDCDCD;}
div.zoomDiv{z-index:999;position:absolute;top:0px;left:0px;width:200px;height:200px;background:#ffffff;border:1px solid #CCCCCC;display:none;text-align:center;overflow:hidden;}
div.zoomMask{position:absolute;background:url(“images/mask.png”) repeat scroll 0 0 transparent;cursor:move;z-index:1;}
//Instantiation of custom panel classes
/** ********title*************/
$options = array();
$boxinfo = array ('title '=>' parameter fills','id'=>'ashubox',' page '=>array ('post'),'context'=>'normal',' priority '=>' low','callback'=>");$options[] = array(" name "=>" product thumbnail upload ",
“type” => “title”);$options[] = array(
"name"=>"thumbnail 1",
“desc” => “”,
“id” => “ashu_upimg01”,
“std” => “”,
"button_label"=>'Upload picture',
“type” => “media”
);
$options[] = array(
"name"=>"thumbnail 2",
“desc” => “”,
“id” => “ashu_upimg02”,
“std” => “”,
"button_label"=>'Upload picture',
“type” => “media”
);
$options[] = array(
"name"=>"thumbnail 3",
“desc” => “”,
“id” => “ashu_upimg03”,
“std” => “”,
"button_label"=>'Upload picture',
“type” => “media”
);
$options[] = array(
"name"=>"thumbnail 4",
“desc” => “”,
“id” => “ashu_upimg04”,
“std” => “”,
"button_label"=>'Upload picture',
“type” => “media”
);
$options[] = array(
"name"=>"thumbnail 5",
“desc” => “”,
“id” => “ashu_upimg05”,
“std” => “”,
"button_label"=>'Upload picture',
“type” => “media”
);
$new_box = new ashu_meta_box($options, $boxinfo);
?>
<div class=”box”>
<div class=”tb-booth tb-pic tb-s310″>
<? php if ( get_post_meta($post->ID, ‘ashu_upimg01’, true) ) {?>
<a href=”<? php echo get_post_meta($post->ID,”ashu_upimg01″,true);?>”><img src=”<? php echo get_post_meta($post->ID,”ashu_upimg01″,true);?>”rel=”<? php echo get_post_meta($post->ID,”ashu_upimg01″,true);?>”class=”jqzoom” /></a>
<? php }?>
</div>
<ul class=”tb-thumb” id=”thumblist”>
<? php if ( get_post_meta($post->ID, ‘ashu_upimg01’, true) ) {?>
<li class=”tb-selected”><div class=”tb-pic tb-s40″><a href=”javascript:void(0);”><img src=”<? php echo get_post_meta($post->ID,”ashu_upimg01″,true);?>”mid=”<? php echo get_post_meta($post->ID,”ashu_upimg01″,true);?>”big=”<? php echo get_post_meta($post->ID,”ashu_upimg01″,true);?>”></a></div></li>
<? php }else{?><li class=”tb-selected”><div class=”tb-pic tb-s40″></div></li> <? php }?>
<? php if ( get_post_meta($post->ID, ‘ashu_upimg02’, true) ) {?>
<li><div class=”tb-pic tb-s40″><a href=”javascript:void(0);”><img src=”<? php echo get_post_meta($post->ID,”ashu_upimg02″,true);?>”mid=”<? php echo get_post_meta($post->ID,”ashu_upimg02″,true);?>”big=”<? php echo get_post_meta($post->ID,”ashu_upimg02″,true);?>”></a></div></li>
<? php }else{?><li><div class=”tb-pic tb-s40″></div></li> <? php }?>
<? php if ( get_post_meta($post->ID, ‘ashu_upimg03’, true) ) {?>
<li><div class=”tb-pic tb-s40″><a href=”javascript:void(0);”><img src=”<? php echo get_post_meta($post->ID,”ashu_upimg03″,true);?>”mid=”<? php echo get_post_meta($post->ID,”ashu_upimg03″,true);?>”big=”<? php echo get_post_meta($post->ID,”ashu_upimg03″,true);?>”></a></div></li>
<? php }else{?><li><div class=”tb-pic tb-s40″></div></li> <? php }?>
<? php if ( get_post_meta($post->ID, ‘ashu_upimg04’, true) ) {?>
<li><div class=”tb-pic tb-s40″><a href=”javascript:void(0);”><img src=”<? php echo get_post_meta($post->ID,”ashu_upimg04″,true);?>”mid=”<? php echo get_post_meta($post->ID,”ashu_upimg04″,true);?>”big=”<? php echo get_post_meta($post->ID,”ashu_upimg04″,true);?>”></a></div></li>
<? php }?>
<? php if ( get_post_meta($post->ID, ‘ashu_upimg05’, true) ) {?>
<li><div class=”tb-pic tb-s40″><a href=”javascript:void(0);”><img src=”<? php echo get_post_meta($post->ID,”ashu_upimg05″,true);?>”mid=”<? php echo get_post_meta($post->ID,”ashu_upimg05″,true);?>”big=”<? php echo get_post_meta($post->ID,”ashu_upimg05″,true);?>”></a></div></li>
<? php }?>
</ul>
</div>
metaboxclass.php:
- <? php
- /*
- Wordpress article custom field class file
- Version: 1.0
- Author: Trees are my friends
- Author URI: http://www.ashuwp.com
- License: http://www.ashuwp.com/courses/highgrade/298.html
- */
- class ashu_meta_box{
- var $options;
- var $boxinfo;
- //constructor
- function ashu_meta_box($options,$boxinfo){
- $this->options = $options;
- $this->boxinfo = $boxinfo;
- add_action(‘admin_menu’, array(&$this, ‘init_boxes’));
- add_action(‘save_post’, array(&$this, ‘save_postdata’));
- }
- //initialize
- function init_boxes(){
- $this->add_script_and_styles();
- $this->create_meta_box();
- }
- //Load css and js scripts
- function add_script_and_styles(){
- if(basename( $_SERVER[‘PHP_SELF’]) == “page.php”
- || basename( $_SERVER[‘PHP_SELF’]) == “page-new.php”
- || basename( $_SERVER[‘PHP_SELF’]) == “post-new.php”
- || basename( $_SERVER[‘PHP_SELF’]) == “post.php”
- || basename( $_SERVER[‘PHP_SELF’]) == “media-upload.php”)
- {
- //Pay attention to the url of the loaded script
- wp_enqueue_style(‘metabox_fields_css’, TEMJS_URI.‘metabox_fields.css’);
- wp_enqueue_script(‘metabox_fields_js’,TEMJS_URI.‘metabox_fields.js’);
- wp_enqueue_style(‘thickbox’);
- wp_enqueue_script(‘media-upload’);
- wp_enqueue_script(‘thickbox’);
- if(isset($_GET[‘hijack_target’]))
- {
- add_action(‘admin_head’, array(&$this,’add_hijack_var’));
- }
- }
- }
- /*************************/
- function add_hijack_var()
- {
- echo “<meta name=’hijack_target’ content='”.$_GET[‘hijack_target’].“‘ />\n”;
- }
- //Create a custom panel
- function create_meta_box(){
- if ( function_exists(‘add_meta_box’) && is_array($this->boxinfo[‘page’]) )
- {
- foreach ($this->boxinfo[‘page’] as $area)
- {
- if ($this->boxinfo[‘callback’] == ”) $this->boxinfo[‘callback’] = ‘new_meta_boxes’;
- add_meta_box(
- $this->boxinfo[‘id’],
- $this->boxinfo[‘title’],
- array(&$this, $this->boxinfo[‘callback’]),
- $area, $this->boxinfo[‘context’],
- $this->boxinfo[‘priority’]
- );
- }
- }
- }
- //Create a display function for a custom panel
- function new_meta_boxes(){
- global $post;
- //Call display function based on type
- foreach ($this->options as $option)
- {
- if (method_exists($this, $option[‘type’]))
- {
- $meta_box_value = get_post_meta($post->ID, $option[‘id’], true);
- if($meta_box_value != “”) $option[‘std’] = $meta_box_value;
- echo ‘<div class=“alt kriesi_meta_box_alt meta_box_’.$ option[‘type’].’meta_box_’.$ this->boxinfo[‘context’]. '”>’;
- $this->$option[‘type’]($option);
- echo ‘</div>’;
- }
- }
- //Hidden domain
- echo‘<input type=“hidden” name=“‘.$ this->boxinfo[‘id’].’_ noncename” id=“‘.$ this->boxinfo[‘id’].’_ noncename” value=“‘.wp_create_nonce( ‘ashumetabox’ ). '” />’;
- }
- //Save field data
- function save_postdata() {
- if( isset( $_POST[‘post_type’] ) && in_array($_POST[‘post_type’],$this->boxinfo[‘page’] ) && (isset($_POST[‘save’]) || isset($_POST[‘publish’]) ) ){
- $post_id = $_POST[‘post_ID’];
- foreach ($this->options as $option) {
- if (! wp_verify_nonce($_POST[$this->boxinfo[‘id’].’_ noncename’], ‘ashumetabox’)) {
- return $post_id ;
- }
- //Determine authority
- if ( ‘page’ == $_POST[‘post_type’] ) {
- if ( ! current_user_can( ‘edit_page’, $post_id ))
- return $post_id ;
- } else {
- if ( ! current_user_can( ‘edit_post’, $post_id ))
- return $post_id ;
- }
- //Convert predefined characters to html entities
- if( $option[‘type’] == ‘tinymce’ ){
- $data = stripslashes($_POST[$option[‘id’]]);
- }elseif( $option[‘type’] == ‘checkbox’ ){
- $data = $_POST[$option[‘id’]];
- }else{
- $data = htmlspecialchars($_POST[$option[‘id’]], ENT_QUOTES,“UTF-8”);
- }
- if(get_post_meta($post_id , $option[‘id’]) == “”)
- add_post_meta($post_id , $option[‘id’], $data, true);
- elseif($data != get_post_meta($post_id , $option[‘id’], true))
- update_post_meta($post_id , $option[‘id’], $data);
- elseif($data == “”)
- delete_post_meta($post_id , $option[‘id’], get_post_meta($post_id , $option[‘id’], true));
- }
- }
- }
- //Display title
- function title($values){
- echo ‘<p>’.$values[‘name’]. '</p>’;
- }
- //Text box
- function text($values){
- if(isset($this->database_options[$values[‘id’]])) $values[‘std’] = $this->database_options[$values[‘id’]];
- echo ‘<p>’.$values[‘name’]. '</p>’;
- echo ‘<p><input type=“text” size=“‘.$ values[‘size’]. '” value=“‘.$ values[‘std’]. '” id=“‘.$ values[‘id’]. '” name=“‘.$ values[‘id’]. '”/>’;
- echo $values[‘desc’]. '<br/></p>’;
- echo ‘<br/>’;
- }
- //Text field
- function textarea($values){
- if(isset($this->database_options[$values[‘id’]])) $values[‘std’] = $this->database_options[$values[‘id’]];
- echo ‘<p>’.$values[‘name’]. '</p>’;
- echo ‘<p><textarea class=“kriesi_textarea” cols=“60” rows=“5” id=“‘.$ values[‘id’]. '” name=“‘.$ values[‘id’]. '”>’.$values[‘std’]. '</textarea>’;
- echo $values[‘desc’]. '<br/></p>’;
- echo ‘<br/>’;
- }
- //Media upload
- function media($values){
- if(isset($this->database_options[$values[‘id’]])) $values[‘std’] = $this->database_options[$values[‘id’]];
- //Picture upload button
- global $post_ID, $temp_ID;
- $uploading_iframe_ID = (int) (0 == $post_ID ? $temp_ID : $post_ID);
- $media_upload_iframe_src = “media-upload.php? post_id=$uploading_iframe_ID”;
- $image_upload_iframe_src = apply_filters(‘image_upload_iframe_src’, “$media_upload_iframe_src&type=image”);
- $button = ‘<a href=“‘.$ image_upload_iframe_src.’& amp;hijack_target=’.$ values[‘id’].’& amp;TB_iframe=true” id=“‘.$ values[‘id’]. '” class=“k_hijack button thickbox” onclick=“return false;” > Upload</a> ';
- //Determine the image format and preview the image
- $image = ”;
- if($values[‘std’] != ”) {
- $fileextension = substr($values[‘std’], strrpos($values[‘std’], ‘.’) + 1);
- $extensions = array(‘png’,’gif’,’jpeg’,’jpg’,’pdf’,’tif’);
- if(in_array($fileextension, $extensions))
- {
- $image = ‘<img src=“‘.$ values[‘std’]. '” />’;
- }
- }
- echo ‘<div id=“‘.$ values[‘id’].’_ div” class=“kriesi_preview_pic”>’.$image . '</div>’;
- echo ‘<p>’.$values[‘name’]. '</p><p>’;
- if($values[‘desc’] != “”) echo ‘<p>’.$values[‘desc’]. '<br/>’;
- echo ‘<input class=“kriesi_preview_pic_input” type=“text” size=“‘.$ values[‘size’]. '” value=“‘.$ values[‘std’]. '” name=“‘.$ values[‘id’]. '”/>’.$button;
- echo ‘</p>’;
- echo ‘<br/>’;
- }
- //radio box
- function radio( $values ){
- if(isset($this->database_options[$values[‘id’]]))
- $values[‘std’] = $this->database_options[$values[‘id’]];
- echo ‘<p>’.$values[‘name’]. '</p>’;
- foreach( $values[‘buttons’] as $key=>$value ) {
- $checked =“”;
- if($values[‘std’] == $key) {
- $checked = ‘checked = “checked”‘;
- }
- echo ‘<input ‘.$checked.’type=“radio” class=“kcheck” value=“‘.$ key. '” name=“‘.$ values[‘id’]. '”/>’.$value;
- }
- }
- //Checkbox
- function checkbox($values){
- echo ‘<p>’.$values[‘name’]. '</p>’;
- foreach( $values[‘buttons’] as $key=>$value ) {
- $checked =“”;
- if( is_array($values[‘std’]) && in_array($key,$values[‘std’])) {
- $checked = ‘checked = “checked”‘;
- }
- echo ‘<input ‘.$checked.’type=“checkbox” class=“kcheck” value=“‘.$ key. '” name=“‘.$ values[‘id’]. '[]”/>’.$value;
- }
- echo ‘<label for=“‘.$ values[‘id’]. '”>’.$values[‘desc’]. '</label><br/></p>’;
- }
- //drop-down box
- function dropdown($values){
- echo ‘<p>’.$values[‘name’]. '</p>’;
- //Select content to enable pages, categories, menus, sidebars and custom content
- if($values[‘subtype’] == ‘page’){
- $select = ‘Select page’;
- $entries = get_pages(‘title_li=&orderby=name’);
- }else if($values[‘subtype’] == ‘cat’){
- $select = ‘Select category’;
- $entries = get_categories(‘title_li=&orderby=name&hide_empty=0’);
- }else if($values[‘subtype’] == ‘menu’){
- $select = ‘Select Menu in page left’;
- $entries = get_terms( ‘nav_menu’, array( ‘hide_empty’ => false ) );
- }else if($values[‘subtype’] == ‘sidebar’){
- global $wp_registered_sidebars;
- $select = ‘Select a special sidebar’;
- $entries = $wp_registered_sidebars;
- }else{
- $select = ‘Select…’;
- $entries = $values[‘subtype’];
- }
- echo ‘<p><select class=“postform” id=“‘. $values[‘id’] . '” name=“‘. $values[‘id’] . '”> ‘;
- echo ‘<option value=“”>’.$select . '</option> ‘;
- foreach ($entries as $key => $entry){
- if($values[‘subtype’] == ‘page’){
- $id = $entry->ID;
- $title = $entry->post_title;
- }else if($values[‘subtype’] == ‘cat’){
- $id = $entry->term_id;
- $title = $entry->name;
- }else if($values[‘subtype’] == ‘menu’){
- $id = $entry->term_id;
- $title = $entry->name;
- }else if($values[‘subtype’] == ‘sidebar’){
- $id = $entry[‘id’];
- $title = $entry[‘name’];
- }else{
- $id = $entry;
- $title = $key;
- }
- if ($values[‘std’] == $id ){
- $selected = “selected=’selected'”;
- }else{
- $selected = “”;
- }
- echo“<option $selected value='”. $id.“‘>”. $title.“</option>”;
- }
- echo ‘</select>’;
- echo $values[‘desc’]. '<br/></p>’;
- echo ‘<br/>’;
- }
- //Editor
- function tinymce($values){
- if(isset($this->database_options[$values[‘id’]]))
- $values[‘std’] = $this->database_options[$values[‘id’]];
- echo ‘<p>’.$values[‘name’]. '</p>’;
- wp_editor( $values[‘std’], $values[‘id’] );
- //wp_editor( $values[‘std’], ‘content’, array(‘dfw’ => true, ‘tabfocus_elements’ => ‘sample-permalink,post-preview’, ‘editor_height’ => 360) );
- //with configuration parameters
- /*wp_editor($meta_box[‘std’],$meta_box[‘name’].’_ value',$settings = array(quicktags=>0,//Cancel html mode
- tinymce=>1,//Visualization mode
- media_buttons=>0,//Cancel media upload
- textarea_rows=>5,//set the number of rows to 5
- editor_class=>”textareastyle”) ); */
- }
- }
- ?>