站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress常用函数add meta box
”
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
<span style="border:1px solid #000; text-align:center; float:right; padding:6px;"><strong>导航:</strong> [[WordPress常用函数(上)| 上一页]] | {{Template:WordPress导航}}</span> <div style="clear:both;"></div> ==说明== add_meta_box在WordPress 2.5版本中被引入。插件开发者可通过该函数在Write Post,Write Page和Write Link编辑页面内添加版块。 ==用法== <?php add_meta_box('id', 'title', 'callback', 'page', 'context', 'priority'); ?> ==示例== 这是一个在文章和页面编辑界面上添加自定义版块的例子,可以在WordPress 2.5或更早版本中运行(未出现add_meta_box函数时)。 <?php /* Use the admin_menu action to define the custom boxes */ add_action('admin_menu', 'myplugin_add_custom_box'); /* Use the save_post action to do something with the data entered */ add_action('save_post', 'myplugin_save_postdata'); /* Adds a custom section to the "advanced" Post and Page edit screens */ function myplugin_add_custom_box() { if( function_exists( 'add_meta_box' )) { add_meta_box( 'myplugin_sectionid', __( 'My Post Section Title', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'post', 'advanced' ); add_meta_box( 'myplugin_sectionid', __( 'My Post Section Title', 'myplugin_textdomain' ), 'myplugin_inner_custom_box', 'page', 'advanced' ); } else { add_action('dbx_post_advanced', 'myplugin_old_custom_box' ); add_action('dbx_page_advanced', 'myplugin_old_custom_box' ); } } /* Prints the inner fields for the custom post/page section */ function myplugin_inner_custom_box() { // Use nonce for verification echo '<input type="hidden" name="myplugin_noncename" id="myplugin_noncename" value="' . wp_create_nonce( plugin_basename(__FILE__) ) . '" />'; // The actual fields for data entry echo '<label for="myplugin_new_field">' . __("Description for this field", 'myplugin_textdomain' ) . '</label> '; echo '<input type="text" name="myplugin_new_field" value="whatever" size="25" />'; } /* Prints the edit form for pre-WordPress 2.5 post/page */ function myplugin_old_custom_box() { echo '< div class="dbx-b-ox-wrapper">' . "\n"; echo '<fieldset id="myplugin_fieldsetid" class="dbx-box">' . "\n"; echo '< div class="dbx-h-andle-wrapper">< h3 class="dbx-handle">' . __( 'My Post Section Title', 'myplugin_textdomain' ) . "</h3></div>"; echo '< div class="dbx-c-ontent-wrapper">< div class="dbx-content">'; // output editing form myplugin_inner_custom_box(); // end wrapper echo "</div></div></fieldset></div>\n"; } /* When the post is saved, saves our custom data */ function myplugin_save_postdata( $post_id ) { // verify this came from the our screen and with proper authorization, // because save_post can be triggered at other times if ( !wp_verify_nonce( $_POST['myplugin_noncename'], plugin_basename(__FILE__) )) { return $post_id; } if ( 'page' == $_POST['post_type'] ) { if ( !current_user_can( 'edit_page', $post_id )) return $post_id; } else { if ( !current_user_can( 'edit_post', $post_id )) return $post_id; } // OK, we're authenticated: we need to find and save the data $mydata = $_POST['myplugin_new_field']; // TODO: Do something with $mydata // probably using add_post_meta(), update_post_meta(), or // a custom table (see Further Reading section below) return $mydata; } ?> '''参数''' '''$id''' (字符)编辑界面的[[HTML]]'id'属性 '''title''' (字符)编辑界面的[[标题]],用户可见 '''callback''' (字符)为编辑界面输出HTML代码的函数 '''page''' (字符)显示编辑界面的Write界面类型(‘文章’,‘页面’或‘[[链接]]’) '''context''' (字符)显示编辑界面的页面部分(‘常规’,‘高级’或‘侧边’(自2.7版本)) '''priority''' (字符)meta box所在内容中的优先级(‘高’或‘低’) ==延伸阅读== *[http://codex.wordpress.org/Migrating_Plugins_and_Themes 整合插件和主题] *[http://codex.wordpress.org/Function_Reference 常用函数] *[http://codex.wordpress.org/Creating_Tables_with_Plugins 用插件创建表格] *[http://codex.wordpress.org/Function_Reference/update_post_meta update_post_meta() ]函数 *[http://codex.wordpress.org/Function_Reference/add_post_meta add_post_meta()] 函数 '''外部资源''' *[http://andrewferguson.net/2008/09/26/using-add_meta_box/ 为插件使用add_meta_box()] —— 如何为插件管理界面使用meta box *[http://wefunction.com/2008/10/tutorial-creating-custom-write-panels-in-wordpress/ 教程:在WordPress中创建自定义Write Panels] —— 用自定义Write选项为文章添加独有数据 ==相关条目== *[[Drupal]] *[[OBLOG]] *[[X-Space]] *[[SaBlog-X]] *[[Bo-Blog]] [[category:WordPress中文文档|G]] [[category:WordPress网站开发|G]] [[category:WordPress开发文档|G]]
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)
本页使用的模板:
模板:WordPress导航
(
查看源代码
)(受保护)