add_post_meta
add_post_meta 函数是 WordPress 中用来给文章或页面添加自定义字段值的一个函数,
其用法与在编写文章时在文章编写界面中利用自定义栏目面板为文章添加自定义字段值的效果是一样的。
add_post_meta函数描述
为文章添加自定义字段。
常见的使用有:文章浏览次数、喜欢按钮、seo插件等常用插件就是使用的自定义字段功能。
参数详解
add_post_meta($post_id, $meta_key, $meta_value,$unique);
$post_id
要添加自定义字段的文章或页面的ID值
$meta_key
自定义字段的键值(名字)
$meta_value
自定义字段的值
$unique
如果已经有相同名字的自定义字段,是否重复添加重名的自定义字段,true为不允许,false为允许
函数使用实例
//为ID为1的文章添加_postviews自定义字段,值为99 add_post_meta(1, "_postviews", "99"); var_dump(get_post_meta(1));echo"<br />"; //为ID为1的文章添加_postviews自定义字段,值为999,并允许重复自定义字段名称 add_post_meta(1, "_postviews", 999,false); var_dump(get_post_meta(1));echo"<br />";
演示效果:
array(1) { ["_postviews"]=> array(1) { [0]=> string(2) "99" } } array(1) { ["_postviews"]=> array(2) { [0]=> string(2) "99" [1]=> string(3) "999" } } //不允许重复自定义字段的代码 add_post_meta(1, "_postviews", "996",true); var_dump(get_post_meta(1));echo"<br />"; add_post_meta(1, "_postviews", "997",true); var_dump(get_post_meta(1));echo"<br />"; array(1) { ["_postviews"]=> array(1) { [0]=> string(3) "996" } } array(1) { ["_postviews"]=> array(1) { [0]=> string(3) "996" } }
add_meta_box
add_meta_box 是 WordPress 进阶使用的一个函数,能用到这个函数那说明你已经比一个普通的博主更了解这个世界瞩目的博客程序了,至少你在它身上已经花了不少功夫了。能用到它,说明你现在正在折腾一个你自己的主题、插件,甚至是在折腾 WordPress 后台了。
好像已经赘述的够多了,下面我们以一个进阶的角度去说明一下这个函数怎么用。
add_meta_box 函数说明
add_meta_box 函数是被用来在文章编辑等页面添加一个设置的区域的函数。
参数说明
<?php add_meta_box( $id, $title, $callback, $post_type, $context, $priority, $callback_args ); ?>
$id HTML 代码中设置区域中id属性的值
$title 区域中的标题名称
$callback 添加的设置区域的显示函数(回调函数)
$post_type 在 post 还是 page 的编辑页面中显示
$context 设置区域的显示位置,主编辑区、边栏、其他
$priority 设置区域显示的优先级
$callback_args 回调函数接受的附加参数
使用实例
function add_xz_box (){//添加设置区域的函数 add_meta_box('xz_box_1', 'add_meta_box 测试', 'xz_box_1','post','side','high',array('str1','str2')); }; //在'add_meta_boxes'挂载 add_xz_box 函数 add_action('add_meta_boxes','add_xz_box'); function xz_box_1($post,$boxargs){//显示设置区域的回调函数 echo"add_meta_box 测试"; };

wordpress后台乱码的解决办法:1、在wordpress的“wp-admin”文件夹下找到“admin.header.php”文件;2、将“charset”属性值设置为“UTF-8”格式即可恢复正常。

wordpress标签错误的解决办法:1、找到并打开wordpress的“wp-includes”目录下的“class-wp.php”文件;2、修改内容为“$pathinfo = isset( $_SERVER['PATH_INFO'] )?mb_convert_encoding($_SERVER['PATH_INFO'],'utf-8','GBK') : '';”即可。

你下载的WordPress主题提供的keywords和description这两个meta标签一般都做得很差,或者根本就不提供,这样不利于SEO。本文将指导你如何给主页、分类、页面以及文章页添加单独的Description 和 Keywords。

wordpress乱码的解决办法:1、修改“wp-config.php”文件里的“define(’DB_CHARSET’, ‘utf8′);”为“define(’DB_CHARSET’, ”);”;2、把新数据库的编码设置成“latin1_swedish_ci”;3、以uft8的格式导入备份的数据库文件即可。

wordpress进不去的解决办法:1、把地址栏“wp-login.php”后面的参数删掉,然后重新输入密码登录;2、登录FTP,下载“pluggable.php”文件,然后找到“ADMIN_COOKIE_PATH”并将它替换为“SITECOOKIEPATH”即可。

wordpress不是saas。SaaS是一种软件销售模式,它主要针对云端应用软件,而WordPress是一款CMS系统,它主要针对网站构建和管理。虽然WordPress可以作为SaaS提供服务,但它本质上不是一种SaaS应用。

本次PHP中文网整合了相关的视频教程,中文手册,以及相关的精选文章安利给大家,统统免费!!!通过我们分享的视频,可随时随地免费观看教程视频,也不需要迅雷或者百度网盘下载了。

wordpress是2003年发布的;Matt于2003年5月27日宣布推出第一版WordPress,受到了社区的欢迎,它基于b2 Cafelog并有显著改进;WordPress的第一个版本包括全新的管理界面、模板、XHTML 1.1兼容模板、内容编辑器。


Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

PhpStorm Mac version
The latest (2018.2.1) professional PHP integrated development tool

SublimeText3 Mac version
God-level code editing software (SublimeText3)

MinGW - Minimalist GNU for Windows
This project is in the process of being migrated to osdn.net/projects/mingw, you can continue to follow us there. MinGW: A native Windows port of the GNU Compiler Collection (GCC), freely distributable import libraries and header files for building native Windows applications; includes extensions to the MSVC runtime to support C99 functionality. All MinGW software can run on 64-bit Windows platforms.

ZendStudio 13.5.1 Mac
Powerful PHP integrated development environment
