站长百科 | 数字化技能提升教程 数字化时代生存宝典
首页
数字化百科
电子书
▼
建站程序
开发
服务器
办公软件
开发教程
▼
服务器教程
软件使用教程
运营教程
热门电子书
▼
CSS教程
WordPress教程
导航
程序频道
推广频道
网赚频道
人物频道
网站程序
网页制作
云计算
服务器
CMS
论坛
网店
虚拟主机
cPanel
网址导航
WIKI使用导航
WIKI首页
热点词条
最新资讯
网站程序
站长人物
页面分类
使用帮助
编辑测试
创建条目
网站地图
站长百科导航
站长百科
主机侦探
IDCtalk云说
跨境电商导航
WordPress啦
站长专题
网站推广
网站程序
网站赚钱
虚拟主机
cPanel
网址导航专题
云计算
微博营销
虚拟主机管理系统
开放平台
WIKI程序与应用
美国十大主机
编辑“
WordPress:Shortcode API
”(章节)
人物百科
|
营销百科
|
网赚百科
|
站长工具
|
网站程序
|
域名主机
|
互联网公司
|
分类索引
跳转至:
导航
、
搜索
警告:
您没有登录。如果您做出任意编辑,您的IP地址将会公开可见。如果您
登录
或
创建
一个账户,您的编辑将归属于您的用户名,且将享受其他好处。
反垃圾检查。
不要
加入这个!
=== 属性 === The raw $atts array may include any arbitrary attributes that are specified by the user. In order to help set default values for missing attributes, and eliminate any attributes that are not recognized by your shortcode, the API provides a shortcode_atts() function. raw $atts数组可能包含用户规定的任何任意的属性。为了为丢失的属性设置默认值并且删除不是你的简码组织的属性,API提供了shortcode_atts()函数。 shortcode_atts() resembles the wp_parse_args() function, but has some important differences. Its parameters are: shortcode_atts()类似与wp_parse_args()函数,但是两者之间有一些关键的不同点。shortcode_atts()的参数是: shortcode_atts( $defaults_array, $atts ); shortcode_atts( $defaults_array, $atts ); Both parameters are required. $defaults_array is an associative array that specifies the recognized attribute names and their default values. $atts is the raw attributes array as passed into your shortcode handler. shortcode_atts() will return a normalized array containing all of the keys from the $defaults_array, filled in with values from the $atts array if present. For example: 两个参数都需要。$defaults_array是一个联合的数组,明确规定了组织的属性名称和默认值。 $atts是raw 属性数组,传递到你的简码处理器。shortcode_atts()会返回规格化的数组,包含所有来自$defaults_array的键,如果有来自$atts array的参数值,就会被填上这个值。例如: $a = shortcode_atts( array( 'title' => 'My Title' 'foo' => 123, ), $atts ); $a = shortcode_atts( array( 'title' => 'My Title' 'foo' => 123, ), $atts ); If $atts were to contain array( 'foo' => 456, 'bar' => 'something' ), the resulting $a would be array( 'title' => 'My Title', 'foo' => 456 ). The value of $atts['foo'] overrides the default of 123. $atts['title'] is not set, so the default 'My Title' is used. And there is no 'bar' item in the defaults array, so it is not included in the result. 如果$atts将要包含数组( 'foo' => 456, 'bar' => 'something' ),结果$a会是数组( 'title' => 'My Title', 'foo' => 456 )。$atts['foo']的值取消了默认值123。$atts['title']没有设置,因此使用了默认的'我的标题'。而且默认数组中没有'bar',因此结果中也没有。 A suggested code idiom for declaring defaults and parsing attributes in a shortcode handler is as follows: 短码处理器中用来声明默认和解析属性的暗示的代码表述是: function my_shortcode_handler( $atts, $content = null ) { extract( shortcode_atts( array( 'attr_1' => 'attribute 1 default', 'attr_2' => 'attribute 2 default', // ...etc ), $atts ) ); } function my_shortcode_handler( $atts, $content = null ) { extract( shortcode_atts( array( 'attr_1' => 'attribute 1 default', 'attr_2' => 'attribute 2 default', // ...etc ), $atts ) ); } This will parse the attributes, set default values, eliminate any unsupported attributes, and (using extract()) store the results in local variables named for the attribute keys - $attr_1, $attr_2 and so on. In other words, the array of defaults approximates a list of local variable declarations. (extract() is safe to use in this context without special flags to handle collisions because shortcode_atts() will strip out any keys not included in the defaults array). 这会解析属性,设置默认值,删除任何无支持的属性,并且(使用extract())将结果储存在本地变数中,命名为属性键-$attr_1, $attr_2 等等。换句话说,默认的数组接近与本地变数声明的一个列表。(在这个文本中使用extract(),非常安全,没有特别的标记处理冲突,因为shortcode_atts()会剥去任何默认数组中不包含的键)。
摘要:
请注意,您对站长百科的所有贡献都可能被其他贡献者编辑,修改或删除。如果您不希望您的文字被任意修改和再散布,请不要提交。
您同时也要向我们保证您所提交的内容是您自己所作,或得自一个不受版权保护或相似自由的来源(参阅
Wordpress-mediawiki:版权
的细节)。
未经许可,请勿提交受版权保护的作品!
取消
编辑帮助
(在新窗口中打开)