admin管理员组文章数量:1419656
I am trying to create a shortcode with an array as input like so
function product_gallery_shortcode($atts) {
extract(shortcode_atts(array(
'product_id' => '31',
'prodvid' => false,
'youtubeids'=>'',//['lbRqMddP2jo','eFAxx817rC0'],
'thumbnr' =>2
), $atts));
I like to loop throught the youtube id's but i don't know how to initialize the youtubeids as an array
so it reads
'youtubeids'=> array('lbRrePOP2jo','eFAxx17rC0'),
regards
I am trying to create a shortcode with an array as input like so
function product_gallery_shortcode($atts) {
extract(shortcode_atts(array(
'product_id' => '31',
'prodvid' => false,
'youtubeids'=>'',//['lbRqMddP2jo','eFAxx817rC0'],
'thumbnr' =>2
), $atts));
I like to loop throught the youtube id's but i don't know how to initialize the youtubeids as an array
so it reads
'youtubeids'=> array('lbRrePOP2jo','eFAxx17rC0'),
regards
Share Improve this question edited Mar 5, 2013 at 11:46 alex asked Mar 5, 2013 at 11:41 alexalex 1,1123 gold badges17 silver badges39 bronze badges 2 |4 Answers
Reset to default 4Ok found a solution
function product_gallery_shortcode($atts) {
extract(shortcode_atts(array(
'product_id' => '31',
'prodvid' => false,
'youtubeids'=> '',
'thumbnr' =>2
), $atts));
etc
and i had to turn youtubeids into an array again
$youtubeidsnew = array();
$youtubeidsnew = explode(',', $youtubeids);
I found the best solution for this problem. If you want use array for input of shortcode use this:
function product_gallery_shortcode($atts) {
extract(shortcode_atts(array(
'product_id' => '31',
'prodvid' => false,
'youtubeids'=> array(),
'thumbnr' =>2
), $atts));
etc
$youtubeids = $atts[youtubeids];
$youtubeids = explode(',', $youtubeids);
In your shortcode input you can use the following for each array index:
[myshortcode youtubeids="index0,index2,index3"]
Simple way I use:
[my param="key1=value1&key2=value2"]
in shortcode callback, just do:
parse_str( str_replace("&", "&", $attrs['param']), $array);
// var_dump( $array );
Could you not just do:
extract(shortcode_atts(array(
'product_id' => '31',
'prodvid' => false,
'youtubeids'=>array('lbRrePOP2jo','eFAxx17rC0'),
'thumbnr' =>2
), $atts));
本文标签: shortcodeHow can i put an array as variable in shortcodeatts
版权声明:本文标题:shortcode - How can i put an array as variable in shortcode_atts? 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745314813a2653102.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
$youtubeids
holds that array... – kaiser Commented Mar 5, 2013 at 11:49