自定义帖子的自定义元框

时间:2013-12-08 13:09:49

标签: php wordpress wordpress-theming

我想创建一个自定义元框。现在如果有人想要发布他或她必须填写自定义元框。如何做?请告诉我如何做到这一点。

1 个答案:

答案 0 :(得分:0)

您可以使用add_meta_box()功能

在自定义帖子类型中添加元框
<?php
       add_action( 'add_meta_boxes', 'add_custom_metaboxes' );
 ?>

添加Meta Box: -

<?php
     // Method for add metaboxes.
    function add_custom_metaboxes() {
       add_meta_box('meta_box_id', 'Meta Box title', 'your_callback_function', 'custom_post_type', 'side', 'default');
     }

为Metabox生成HTML: -

<?php
 function your_callback_function() {
       global $post;
   // Code for your metabox fields goes here.
 }
?>

一些参考链接: -
http://wptheming.com/2010/08/custom-metabox-for-post-type/
http://wp.smashingmagazine.com/2011/10/04/create-custom-post-meta-boxes-wordpress/

相关问题