หน้า 1 จากทั้งหมด 1

สอนสร้าง Plugin WordPress (16) : ตัวอย่างการสร้าง Custom Meta Boxes

โพสต์แล้ว: 25/10/2016 12:02 pm
โดย thatsawan
Custom Meta Boxes
  • พูดให้เข้าใจๆ ง่ายๆ มันก็คือการเพิ่ม Box ของฟิลด์ใน Post type ต่างๆ โดยสามารถจะระบุได้ว่าจะว่าง box นี้ที่ตำแหน่งใหน

โค้ด: เลือกทั้งหมด

add_meta_box( string $id, string $title, callable $callback, string|array|WP_Screen $screen = null, string $context = 'advanced', string $priority = 'default', array $callback_args = null ) 
ตัวอย่างการใช้งาน

โค้ด: เลือกทั้งหมด

function custom_meta_box_markup()
{
    echo 'hello';
}

function add_custom_meta_box()
{
    add_meta_box("demo-meta-box", "Custom Meta Box", "custom_meta_box_markup", "post", "side", "high", null);
}

add_action("add_meta_boxes", "add_custom_meta_box"); 
*"post", post type ที่ต้องการ Add
* "side", ตำแหน่งที่ต้องการ
* "high" ระดับในหน้าเเสดงผล

ผลที่ได้
รูปภาพ



ตัวอย่างการใช้งาน

โค้ด: เลือกทั้งหมด

function custom_meta_box_markup()
{
    echo '<label for="my_meta_box_text">Text Label</label>
    <input type="text" name="my_meta_box_text" id="my_meta_box_text" />';
}

function add_custom_meta_box()
{
    add_meta_box("demo-meta-box", "Custom Meta Box", "custom_meta_box_markup", "post", "side", "high", null);
}

add_action("add_meta_boxes", "add_custom_meta_box"); 
ผลที่ได้
รูปภาพ

ศึกษาเพิ่มเติมที่นี่
https://developer.wordpress.org/referen ... _meta_box/

Re: สอนสร้าง Plugin WordPress (16) : ตัวอย่างการสร้าง Custom Meta Boxes

โพสต์แล้ว: 25/10/2016 9:47 pm
โดย mindphp
รวมกระทู้ บทความสอนสร้าง Plugin WordPress
https://www.mindphp.com/forums/viewtopic ... 25&t=36079