मैं निम्नलिखित कोड जो व्यवस्थापक पानी का छींटा और बाद संपादन विंडो के लिए एक कस्टम मेटा बॉक्स के लिए एक कस्टम पोस्ट प्रकार कहते हैं:में एक कस्टम पोस्ट प्रकार के लिए कई मेटा-बक्से जोड़ना वर्डप्रेस
function teasers_custom_init() {
$labels = array(
'name' => 'Teasers',
'singular_name' => 'Teaser',
'add_new' => 'Add New',
'add_new_item' => 'Add New Teasers',
'edit_item' => 'Edit Teaser',
'new_item' => 'New Teaser',
'all_items' => 'All Teasers',
'view_item' => 'View Teaser',
'search_items' => 'Search Teasers',
'not_found' => 'No teasers found',
'not_found_in_trash' => 'No teasers found in Trash',
'parent_item_colon' => 'Parent Page',
'menu_name' => 'Teasers'
);
$args = array(
'labels' => $labels,
'description' => 'set slider panels with loop times',
'public' => true,
'publicly_queryable' => true,
'show_ui' => true,
'show_in_menu' => true,
'query_var' => true,
'rewrite' => array('slug' => 'Teasers'),
'capability_type' => 'page',
'has_archive' => true,
'hierarchical' => true,
'menu_position' => 60,
'supports' => array('title', 'thumbnail', 'page-attributes'),
);
register_post_type('teasers', $args);
}
add_action('init', 'teasers_custom_init');
//adding the meta box when the admin panel initialises
add_action("admin_init", "admin_init");
// this adds the save teaser function on save post
add_action('save_post', 'save_teaser');
function admin_init(){
add_meta_box('teaser_loop', 'Loop Time', 'loop_meta', 'teasers', 'normal', 'default');
}
// callback function of add meta box that displays the meta box in the post edit screen
function loop_meta($post, $args){
$teaser_loop = get_post_meta($post->ID, 'teaser_loop', true);
?>
<label>Teaser Loop: </label><input type="text" name="teaser_loop" value="<?php echo $teaser_loop; ?>" /><br/>
<?php
}
// saving the teaser
function save_teaser(){
global $post;
update_post_meta($post->ID, 'teaser_loop', $_POST['teaser_loop']);
}
मेरा प्रश्न अगर मैं एक अतिरिक्त मेटा बॉक्स जोड़ना चाहता हूं, तो सबसे अच्छा तरीका क्या है?
मैंने admin_init फ़ंक्शन में एक और add_meta_box कॉल जोड़ने का प्रयास किया और इस मेटा बॉक्स HTML के लिए अतिरिक्त कॉलबैक फ़ंक्शन भी बनाया लेकिन फ्रंट एंड पर कुछ भी उत्पन्न नहीं हुआ। कोई संकेतक महान होगा।
संपादित करें: तो यह (यह काम करता है) मैं इसे कैसे एक से अधिक मेटा बॉक्स के लिए किया था:
//adding the meta box when the admin panel initialises
add_action("admin_init", "admin_init");
// this adds the save teaser function on save post
add_action('save_post', 'save_teaser');
function admin_init(){
add_meta_box('teaser_loop', 'Loop Time', 'loop_meta_1', 'teasers', 'normal', 'default');
add_meta_box('teaser_link', 'Teaser Link', 'loop_meta_2', 'teasers', 'normal', 'default');
}
// back function of add meta box that displays the meta box in the post edit screen
function loop_meta_1($post, $args){
$teaser_loop = get_post_meta($post->ID, 'teaser_loop', true);
?>
<label>Teaser Loop: </label><input type="text" name="teaser_loop" value="<?php echo $teaser_loop; ?>" /><br/>
<?php
}
function loop_meta_2($post, $args){
$teaser_link = get_post_meta($post->ID, 'teaser_link', true);
?>
<label>Teaser Link: </label><input type="text" name="teaser_link" value="<?php echo $teaser_link; ?>" /><br/>
<?php
}
// saving the teaser
function save_teaser(){
global $post;
update_post_meta($post->ID, 'teaser_loop', $_POST['teaser_loop']);
update_post_meta($post->ID, 'teaser_link', $_POST['teaser_link']);
}
तुम भी http पर इस पूछ सकते: //wordpress.stackex change.com/ – Joren
या [codereview.se] पर, क्योंकि यह अनुकूलित करने के उद्देश्य से काम कर रहे कोड का काम कर रहा है। – brasofilo
मैंने बक्षीस डाला है क्योंकि वेब पर कहीं भी इस समस्या का गतिशील दृष्टिकोण नहीं है। मैं सोच रहा था कि इष्टतम समाधान क्या होगा जो सभी रूप तत्वों को शामिल करता है। – Joren