• Resolved Danzel707

    (@danzel707)


    When I nest the accordion within a article tag, then the option ‘open first’ doesn’t work. If I remove the article tag then it works.

    I’m using your code within a loop:

    `
    <?php if(have_posts()): while(have_posts()):the_post();?>
    <article>
    <h3 class=”accordion-title”><?php the_title();?></h3>
    <div class=”accordion-content”>
    <?php the_content();?>
    </div>
    </article>
    <?php endwhile;endif;?><!– End Loop –>

    !function(o){"use strict";var e=o(".accordion-title"),s=o(".accordion-content").hide(),n=o(".accordion-content:first-of-type"),t=250,i={autoClose:!0,openFirst:!0,openAll:!1,clickToClose:!0,scroll:!1};"undefined"!=typeof accordionSettings&&(i=accordionSettings),i.openAll?(s.show(),e.addClass("open")):i.openFirst&&(n.prev().addClass("open"),n.slideDown(t)),e.click(function(){return o(this).hasClass("open")?i.clickToClose&&(o(this).next().slideUp(t),o(this).removeClass("open")):(i.autoClose&&(s.slideUp(t),e.removeClass("open")),o(this).next().slideDown(t,function(){i.scroll&&o("html, body").animate({scrollTop:o(this).prev().offset().top},t)}),o(this).addClass("open")),!1})}(jQuery);

Viewing 2 replies - 1 through 2 (of 2 total)
  • Plugin Author philbuchanan

    (@philbuchanan)

    The plugin isn’t meant to be stripped apart into it’s various pieces (HTML and JavaScript). It should really be used as is with the shortcodes provided. I can’t really offer support if you pull the pieces apart as you’re essentially asking me to write some custom code for you specifically.

    That said, the issue is that the JavaScript relies on the parent/child relationships of the various HTML elements within the .accordion-content div. So you can’t simply introduce a new HTML element between the accordion items, as you have done here. You should be able to modify the JavaScript yourself to fix the issue. You can see in the source file where the plugin determines what the first accordion is (the first child node of the .accordion-content div). This block will also be important to note/modify.

    Please also note that if you modify the plugin code any changes will be deleted next time you update the plugin.

    Thread Starter Danzel707

    (@danzel707)

    thank you, I will see if I can add some custom code, I’ve already tried to change (“.accordion-content:first-of-type”) to (“article:first-of-type”), but that didn’t work.

Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘Open first item doesn't work when accordion is nested in article tag’ is closed to new replies.