我正在为我的 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]
所以,基本上它是两个不同的简码(幻灯片和幻灯片),我需要设置每个“幻灯片”简码的宽度。如何从父“幻灯片”短代码中获取“宽度”属性并将其传递给每个子“幻灯片”?
//Create slideshow wrapper div
function shortcode_slideshow($atts, $content = null){
$return = '<div class="slideshow">';
$return .= do_shortcode($content);
$return .= '</div><!-- end slideshow -->';
return $return;
}
//Create each slide HTML
function shortcode_slide($atts, $content = null){
$return = '<a class="dolightbox" href="'.$content.'">';
$return .= '<img src="'.$content.'" /></a>';
return $return;
}
add_shortcode('slideshow', 'shortcode_slideshow');
add_shortcode('slide', 'shortcode_slide');