Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/lua/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 获取具有多个属性的短代码_Php_Wordpress_Plugins_Shortcode - Fatal编程技术网

Php 获取具有多个属性的短代码

Php 获取具有多个属性的短代码,php,wordpress,plugins,shortcode,Php,Wordpress,Plugins,Shortcode,我想创建具有多个属性的shortcode。 但我只能处理单个属性,不能处理多个属性 我只能做到这一点: add_shortcode('test','get_shortcode'); 但是我想创建这样的shortcode: add_shortcode('test id=1 title=test','get_shortcode'); 我想在我的页面中这样称呼这个shortcode do_shortcode('[test id="1" title="test"]'); 您好,添加您的函数$att

我想创建具有多个属性的
shortcode
。 但我只能处理单个属性,不能处理多个属性

我只能做到这一点:

add_shortcode('test','get_shortcode');
但是我想创建这样的
shortcode

add_shortcode('test id=1 title=test','get_shortcode');
我想在我的页面中这样称呼这个
shortcode

do_shortcode('[test id="1" title="test"]');

您好,添加您的函数$atts,就像这样

function bartag_func( $atts ) {
$atts = shortcode_atts(
    array(
        'foo' => 'no foo',
        'bar' => 'default bar',
    ), $atts, 'bartag' );

return 'bartag: ' . $atts['foo'] . ' ' . $atts['bar'];
}

add_shortcode( 'bartag', 'bartag_func' );
它的显示结果类似于
[bartag foo=“考拉”bar=“熊”]