Wordpress元框 - 如何向页面添加元框?

时间:2015-01-08 06:37:09

标签: php wordpress wordpress-plugin meta-boxes

如何将meta-box添加到网页和帖子中?

我已将code添加到themes/package/demo.php,我可以在帖子中看到标准字段高级字段,但我< strong>仅在页面中查看标准字段

我还可以在网页中包含高级字段吗?

这里有一个answer,但我应该在哪里放下这个脚本?

function meta_box_video()
{                                      // --- Parameters: ---
    add_meta_box( 'video-meta-box-id', // ID attribute of metabox
                  'Video Embed',       // Title of metabox visible to user
                  'meta_box_callback', // Function that prints box in wp-admin
                  'page',              // Show box for posts, pages, custom, etc.
                  'normal',            // Where on the page to show the box
                  'high' );            // Priority of box in display order
}

1 个答案:

答案 0 :(得分:1)

使用此代码:

function myplugin_add_meta_box() {

$screens = array( 'post', 'page' );

foreach ( $screens as $screen ) {

    add_meta_box(
        'myplugin_sectionid',
        __( 'My Post Section Title', 'myplugin_textdomain' ),
        'myplugin_meta_box_callback',
        $screen
    );
}
} add_action( 'add_meta_boxes', 'myplugin_add_meta_box' );