add_meta_box()为博客后台管理界面添加一个Meta模块

目录

描述

译文

add_meta_box在WordPress 2.5版本中被引入。插件开发者可通过该函数在Write Post,Write Page和Write Link编辑页面内添加版块。

原文

add_meta_box() 函数是在 WordPress 2.5 添加的,用来给插件开发者添加 Meta模块 到管理界面。 

This function should be called from the add_meta_boxes_{post_type} or 'add_meta_boxes' action. The former is preferable as it avoids triggering needless callbacks for other post types. These actions were introduced in Version 3.0; in prior versions, use 'admin_init' instead.

add_meta_box() 描述

用法

<?php
   add_meta_box
$id$title$callback$screen$context,
         
$priority$callback_args );
?>

add_meta_box() 用法

参数

$id

(string) (必填) Meta模块的 HTML“ID”属性

默认值: None

$title

(string) (必填) Meta模块的标题,对用户可见

默认值: None

$callback

(callback) (必填) 为Meta模块输出 HTML代码的函数

默认值: None

$screen

(string) (可选) The type of writing screen on which to show the edit screen section (examples include 'post','page','dashboard','link','attachment','custom_post_type','comment' where custom_post_type is the custom post type slug)

默认值: null

$context

(string) (可选) The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side'). (Note that 'side' doesn't exist before 2.7)

默认值: 'advanced'

$priority

(string) (可选) The priority within the context where the boxes should show ('high', 'core', 'default' or 'low')

默认值: 'default'

$callback_args

(array) (可选) Arguments to pass into your callback function. The callback will receive the $post object and whatever parameters are passed through this variable.

默认值: null

add_meta_box() 参数

返回值

None.

add_meta_box() 返回值

示例

Procedural

Here is an example that adds a custom section to the post and page editing screens:

Class

This is an example of how to add a meta box from inside a class

Callback args

The $callback_args array will be passed to the callback function as the second argument. The first argument is the post's $post object.

add_meta_box() 示例

源文件

add_meta_box() 函数的代码位于 wp-admin/includes/template.php.

add_meta_box() 源文件