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

แชร์ ความรู้สำหรับพัฒนา plugin ของ Wordpress

Moderator: mindphp, ผู้ดูแลกระดาน

ภาพประจำตัวสมาชิก
thatsawan
PHP VIP Members
PHP VIP Members
โพสต์: 28508
ลงทะเบียนเมื่อ: 31/03/2014 10:02 am
ติดต่อ:

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

โพสต์ที่ยังไม่ได้อ่าน โดย 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/
ภาพประจำตัวสมาชิก
mindphp
ผู้ดูแลระบบ MindPHP
ผู้ดูแลระบบ MindPHP
โพสต์: 41131
ลงทะเบียนเมื่อ: 22/09/2008 6:18 pm
ติดต่อ:

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

โพสต์ที่ยังไม่ได้อ่าน โดย mindphp »

รวมกระทู้ บทความสอนสร้าง Plugin WordPress
https://www.mindphp.com/forums/viewtopic ... 25&t=36079
ติดตาม VDO: http://www.youtube.com/c/MindphpVideoman
ติดตาม FB: https://www.facebook.com/pages/MindphpC ... 9517401606
หมวดแชร์ความรู้: https://www.mindphp.com/forums/viewforum.php?f=29
รับอบรม และพัฒนาระบบ: https://www.mindphp.com/forums/viewtopic.php?f=6&t=2042
ตอบกลับโพส
  • Similar Topics
    ตอบกลับ
    แสดง
    โพสต์ล่าสุด

ผู้ใช้งานขณะนี้

สมาชิกกำลังดูบอร์ดนี้: ไม่มีสมาชิกใหม่ และบุคลทั่วไป 26