Php 如何在嵌套的短代码中获取属性?

Php 如何在嵌套的短代码中获取属性?,php,wordpress,shortcode,Php,Wordpress,Shortcode,我正在为我的Wordpress主题创建一个幻灯片短代码,但遇到了一个小问题。这就是短代码的外观: [slideshow width=500] [slide]http://example.com/image1.jpg[/slide] [slide]http://example.com/image2.jpg[/slide] [slide]http://example.com/image3.jpg[/slide] [/slideshow] 所以,基本上是两个不同的短代码(幻灯

我正在为我的Wordpress主题创建一个幻灯片短代码,但遇到了一个小问题。这就是短代码的外观:

[slideshow width=500]
    [slide]http://example.com/image1.jpg[/slide]
    [slide]http://example.com/image2.jpg[/slide]
    [slide]http://example.com/image3.jpg[/slide]
[/slideshow]
所以,基本上是两个不同的短代码(幻灯片和幻灯片),我需要设置每个“幻灯片”短代码的宽度。如何从父“幻灯片放映”快捷码中获取“宽度”属性并将其传递给每个子“幻灯片”

//创建幻灯片包装div
函数快捷码\幻灯片放映($atts,$content=null){
$return='';
$return.=do_短代码($content);
$return.='';
return$return;
} 
//创建每张幻灯片的HTML
函数快捷码\u幻灯片($atts,$content=null){
$return='';
return$return;
}
添加快捷代码(“幻灯片放映”、“快捷代码”幻灯片放映);
添加快捷代码(“幻灯片”、“快捷代码”幻灯片);

最后使用全局变量将值传递到第二个快捷码函数中。我想也许有一种本地的Wordpress方法可以做到这一点,但我显然没有

//Create slideshow wrapper div
$globalWidth = NULL; 

function shortcode_slideshow($atts, $content = null){ 
    extract(shortcode_atts( array('width' => ''), $atts));
    global $globalWidth;
    $return = '<div class="slideshow">';
    $return .= do_shortcode($content); 
    $return .= '</div><!-- end slideshow -->'; 

    return $return; 
} 

//Create each slide HTML 
function shortcode_slide($atts, $content = null){
    global $globalWidth;
    $return = '<img width="'.$globalWidth.'" src="'.$content.'" />'; 

    return $return; 
}

add_shortcode('slideshow', 'shortcode_slideshow');
add_shortcode('slide', 'shortcode_slide');
//创建幻灯片包装div
$globalWidth=NULL;
函数快捷码\幻灯片放映($atts,$content=null){
提取(短码_atts(数组('width'=>'',$atts));
全球$globalWidth;
$return='';
$return.=do_短代码($content);
$return.='';
return$return;
} 
//创建每张幻灯片的HTML
函数快捷码\u幻灯片($atts,$content=null){
全球$globalWidth;
$return='';
return$return;
}
添加快捷代码(“幻灯片放映”、“快捷代码”幻灯片放映);
添加快捷代码(“幻灯片”、“快捷代码”幻灯片);

我想,我们需要添加
$globalWidth=$width编码到第一个函数中。在一个页面中使用多个此短代码实例如何?
//Create slideshow wrapper div
$globalWidth = NULL; 

function shortcode_slideshow($atts, $content = null){ 
    extract(shortcode_atts( array('width' => ''), $atts));
    global $globalWidth;
    $return = '<div class="slideshow">';
    $return .= do_shortcode($content); 
    $return .= '</div><!-- end slideshow -->'; 

    return $return; 
} 

//Create each slide HTML 
function shortcode_slide($atts, $content = null){
    global $globalWidth;
    $return = '<img width="'.$globalWidth.'" src="'.$content.'" />'; 

    return $return; 
}

add_shortcode('slideshow', 'shortcode_slideshow');
add_shortcode('slide', 'shortcode_slide');