我正在尝试将jQuery手风琴/标签短信看起来像这样
[accordions]
[accordion title="Accordion 1"]Accordion 1 Content[/accordion]
[accordion title="Accordion 2"]Accordion 2 Content[/accordion]
[accordion title="Accordion 3"]Accordion 3 Content[/accordion]
[/accordions]
我尝试了很多方法,但我似乎无法让它工作
如何做到这一点?
答案 0 :(得分:0)
我还没有测试过这段代码,但这应该可行:
function accordian_open_tag( $atts, $content='' ) {
return '<div class="accordion">{$content}</div>';
}
function accordian_section( $atts, $content='' ) {
$atts = shortcode_atts( array(
'title' => 'default title'
), $atts );
return "<h3><a href=\"#\">{$atts['title']}</a></h3>" .
"<div>{$content}</div>";
}
add_shortcode( 'accordians', 'accordian_open_tag' );
add_shortcode( 'accordian', 'accordian_section' );
加载页面时,您需要运行$(".accordian").accordian()
才能生效。
答案 1 :(得分:0)