-
HuseyinKogo
Hi,
So i need help on getting the first Accordion opened automatically, because i will be using the Accordion on Query Loop block.
-
Hi there,
see here:
https://docs.generateblocks.com/article/accordion-overview/#block-settings-–-accordion-item
Each of the Accordion Item blocks has a block setting option to be Open by Default.
-
HuseyinKogo
Thanks, as it is query loop, i have one accordion in the post template. How can achieve this?
-
HuseyinKogo
any update?
-
Sorry your last reply slipped through our system.
Hmmm… theres no option for that, as effectively each Accordion it outputs is its own accordion block, that all share the same identical settings.The workaround would be:
1. Close the items by default.
2. In a HTML block after the Query Loop add this script:<script> var accordionItem = document.querySelector('.gb-accordion__item'); if (accordionItem) { var button = accordionItem.querySelector('button'); if (button) { button.click(); } } </script>
That will open the first accordion for you.
-
HuseyinKogo
Added it like this, but no luck.
-
The HTML block with the script has to be after the query loop / accordions. Not before it.
-
HuseyinKogo
sorry like?
-
thats correct.
-
HuseyinKogo
however its not working, when the page is loaded only want the first one opened.
-
Alvind
Hi there,
Try replacing David’s code to this:
<script> var accordionItem = document.querySelector('.gb-container-48972393'); if(accordionItem) { accordionItem.classList.add('gb-accordion__item-open'); } </script>
-
HuseyinKogo
great thanks, however i only want one item open at time, is that possible?
-
Alvind
Unfortunately, that would require extensive JavaScript customization, and it’s beyond the scope of what we cover.
Does the accordion really need to be displayed using a query loop? It seems like a single Accordion block would be sufficient as it allows for more control, but perhaps it is not feasible in your use case.
-
HuseyinKogo
If that’s the case, all good. thanks so much for the help guys.
The use of query loop is because i have FAQ as Custom Type Post, filtered by tags
-
Alvind
No problem at all!
- You must be logged in to reply to this topic.