您可以创建一个字符串并对其进行解析。你从
[foo people="name:john,age:51|name:jenny,age:62" something="custom"]
你使用这个代码
add_shortcode("foo", function ($attr, $content, $tag) {
// parsing attributes
$attr["people"] = explode("|", $attr["people"]);
$attr["people"] = array_map(function ($e) {
$tab = [];
foreach (explode(",", $e) as $raw_tab) {
$tab2 = explode(":", $raw_tab);
$tab[$tab2[0]] = $tab2[1];
}
return $tab;
}, $attr["people"]);
/*
$attr = array(
\'people\' => array(
0 => array(
\'name\' => \'john\',
\'age\' => \'51\',
),
1 => array(
\'name\' => \'jenny\',
\'age\' => \'62\',
),
),
\'something\' => \'custom\',
);
*/
// generate output
$result = "...";
return $result;
});