jQuery手风琴和Wordpress Shortcode

时间:2011-07-03 19:08:56

标签: jquery wordpress shortcode

我正在尝试将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]

我尝试了很多方法,但我似乎无法让它工作

如何做到这一点?

2 个答案:

答案 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)

>>> my_list[7:10], my_list[2:4] = my_list[2:4], my_list[7:10]
>>> my_list
[0, 1, 7, 8, 9, 4, 5, 6, 2, 3, 10, 11, 12]