โดย thatsawan » 25/10/2016 12:02 pm
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/
[b]Custom Meta Boxes[/b]
[list]พูดให้เข้าใจๆ ง่ายๆ มันก็คือการเพิ่ม Box ของฟิลด์ใน Post type ต่างๆ โดยสามารถจะระบุได้ว่าจะว่าง box นี้ที่ตำแหน่งใหน[/list]
[code=php]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 ) [/code]
[b]ตัวอย่างการใช้งาน[/b]
[code=php]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"); [/code]
*"post", post type ที่ต้องการ Add
* "side", ตำแหน่งที่ต้องการ
* "high" ระดับในหน้าเเสดงผล
ผลที่ได้
[img]http://snap.mindphp.com/index.php?view=2016Oct24_580e268866e87[/img]
[b]ตัวอย่างการใช้งาน[/b]
[code=php]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"); [/code]
ผลที่ได้
[img]http://snap.mindphp.com/index.php?view=2016Oct24_580e299a919ba[/img]
[b]ศึกษาเพิ่มเติมที่นี่[/b]
https://developer.wordpress.org/reference/functions/add_meta_box/