Home Forums Add-ons Flexible Content Field Two Dynamic Bootstrap Accordions


Two Dynamic Bootstrap Accordions

  • I use ACF Flexible Content to create my layouts, sometimes a user will use two Bootstrap Accordions on one page, when they do this the following code no longer works:

    <?php if( have_rows(‘dropdown_area’) ): ?>
    <?php $i = 0; ; while ( have_rows(‘dropdown_area’) ) : the_row(); $i++; $tCount = $i; ?>

    I have tried adding a counter to my flexible content:
    <?php if( have_rows(‘flexible_content’) ): ?>
    <?php $rowCounter = 0; while ( have_rows(‘flexible_content’) ) : the_row(); $rowCounter++; $mCount = $rowCounter ?>

    But can’t get this to echo into my repeater to then make each accordion unique again.

  • A example using bootstrap accordion example from here

    if (have_rows('flex-field')) {
      $accord_count = 0;
      while (have_rows('flex-field')) {
        if (get_row_layout() == 'accordion') {
          if (have_rows('dropdown_area')) {
            $row_count = 0;
              <div class="accordion" id="accordionExample<?php echo $accord_count; ?>">
                  while (have_rows('dropdown_area')) {
                      <div class="card">
                        <div class="card-header" id="heading-<?php echo $accord_count; ?>-<?php echo $row_count; ?>">
                          <h2 class="mb-0">
                            <button class="btn btn-link" type="button" data-toggle="collapse" data-target="#collapse-<?php 
                                    echo $accord_count; ?>-<?php echo $row_count; 
                                    ?>" aria-expanded="<?php 
                                    if ($row_count == 1) {
                                      echo 'true';
                                    } else {
                                      echo 'false';
                                    ?>" aria-controls="collapse-<?php 
                                    echo $accord_count; ?>-<?php echo $row_count; ?>">
                              Collapsible Group Item #1
                        <div id="collapse-<?php echo $accord_count; ?>-<?php echo $row_count;
                                ?>" class="collapse<?php 
                                if ($row_count == 1) {
                                  echo ' show';
                                ?>" aria-labelledby="heading-<?php echo $accord_count; ?>-<?php echo $row_count;
                                ?>" data-parent="#accordionExample<?php echo $accord_count; ?>">
                          <div class="card-body">
                            Anim pariatur cliche reprehenderit, enim eiusmod high life accusamus terry richardson ad squid. 3 wolf moon officia aute, non cupidatat skateboard dolor brunch. Food truck quinoa nesciunt laborum eiusmod. Brunch 3 wolf moon tempor, sunt aliqua put a bird on it squid single-origin coffee nulla assumenda shoreditch et. Nihil anim keffiyeh helvetica, craft beer labore wes anderson cred nesciunt sapiente ea proident. Ad vegan excepteur butcher vice lomo. Leggings occaecat craft beer farm-to-table, raw denim aesthetic synth nesciunt you probably haven't heard of them accusamus labore sustainable VHS.
                  } // end while have_rows('dropdown_area')
          } // end if have_rows('dropdown_area')
        } // end if accordion
      } // end while have_rows('flex-field')
    } // end if have_rows('flex-field')
  • How can I get dynamic data from bootstrap modal?

Viewing 3 posts - 1 through 3 (of 3 total)

You must be logged in to reply to this topic.