I made a Bootstrap 5 sidebar that shows field choices as menu items and under field choices dropdown there are custom post pages who fit the current field choices.
Now I want to make that specific dropdown menu stays open when user press on custom post page who are under the specific dropdown. To open menu I need to add show class, but how can I determine if user chose specific custom post page and how to make if statement in my sidebar to show dropdown opened when clicked on custom post page.
My code:
<?php $field = get_field_object('field_635a79a3e0657'); ?>
<div class="col-md-3">
<div class="flex-shrink-0 p-3 bg-white" style="width: 280px;">
<a href="/" class="d-flex align-items-center pb-3 mb-3 link-dark text-decoration-none border-bottom">
<svg class="bi me-2" width="30" height="24">
<use xlink:href="#bootstrap"></use>
</svg>
<span class="fs-5 fw-semibold">Rokasgrāmata</span>
</a>
<ul class="list-unstyled ps-0">
<?php foreach ($field['choices'] as $value => $label) : ?>
<li class="mb-1">
<button class="btn btn-toggle align-items-center rounded collapsed" data-bs-toggle="collapse" data-bs-target="#<?php echo $value; ?>-collapse" aria-expanded="false">
<?php echo $label; ?>
</button>
<div class="collapse <?php if(1){ echo $rokasgramate_id;}?>" id="<?php echo $value; ?>-collapse" style="">
<?php while ($objects->have_posts()) : $objects->the_post(); ?>
<?php if (get_field('kategorijas') == $value) { ?>
<ul class="btn-toggle-nav list-unstyled fw-normal pb-1 small">
<li><a href="<?php the_permalink(); ?>" class="link-dark rounded"><?php the_title() ?></a></li>
</ul>
<?php } ?>
<?php endwhile; ?>
</div>
</li>
<?php endforeach; ?>
</ul>
</div>
</div>
You must be logged in to reply to this topic.
Welcome to the Advanced Custom Fields community forum.
Browse through ideas, snippets of code, questions and answers between fellow ACF users
Helping others is a great way to earn karma, gain badges and help ACF development!
We use cookies to offer you a better browsing experience, analyze site traffic and personalize content. Read about how we use cookies and how you can control them in our Privacy Policy. If you continue to use this site, you consent to our use of cookies.