在由某些字符分隔的单个变量中传递数据:
[myproduct cols="name,quantity,price" data="name1,5,2.00,name2,3,3.25"]
然后将其分解为一个数组并输出。我没有在这里讨论表标记,但您知道了:
function myproduct_func( $atts ) {
extract( shortcode_atts( array(
\'cols\' => \'none\',
\'data\' => \'none\',
), $atts ) );
$cols = explode(\',\',$cols);
$data = explode(\',\',$data);
$total = count($cols);
$output = "";
foreach($cols as $col):
$output .= "| {$col} ";
endforeach;
$output .= "<br>";
$counter = 1;
foreach($data as $datum):
$output .= "| {$datum} ";
if($counter%$total==0):
$output .= "<br>";
endif;
$counter++;
endforeach;
return $output;
}
add_shortcode( \'myproduct\', \'myproduct_func\' );