Collapsible menu on post sidebar only expands and does not collapse

I’m working to improve an existing wordpress theme that was built for my organization. I’ve run into a problem that I’m not familiar with: the archive menu displayed on each post will only expand, but cannot seem to collapse.

Here’s a link to a live example: https://nabconference.org/shaped-by-the-word/

Scroll enough to get to the sidebar archive and click on a month and you’ll find that the archives cannot be collapsed once expanded.

I’ve considered taking out this archive altogether, but that’s still not the best option.

I’d appreciate any help on this that I can get. I can pull excerpts form the javascript file as needed.

Here’s the code that runs the archive section of sidebar:

<div class=”post-archives”>
<h3>Post Archives</h3>
<?php
// The Query
query_posts( array(
‘posts_per_page’ => -1
) );

$previous_month = false;
$post_date = false;
$semaphore = 0;

// The Loop
while ( have_posts() ) : the_post();

// Consecutive Runs
$previous_month = $post_date;
$post_date = get_the_date(‘F y’);
?>

<!– Repeat –>
<?php if( $post_date != $previous_month && $semaphore == 1 ): $semaphore = 0; ?>
</ul>
</div> <!– /.collapse –>
</div> <!– /.month –>
<?php endif; ?>
<?php if( $post_date != $previous_month && $semaphore == 0 ): $semaphore = 1; ?>
<div class=”month”>
<a class=”month-collapse-btn” role=”button” data-toggle=”collapse” href=”#collapseExample<?= get_the_ID() ?>” aria-expanded=”false” aria-controls=”collapseExample”><?= get_the_date(‘F y’) ?> <i class=”fa fa-caret-down” aria-hidden=”true”></i></a>

<div class=”collapse” id=”collapseExample<?= get_the_ID() ?>”>
<p class=”post-title”><a href=”<?= the_permalink(); ?>”><?php the_title(); ?></a></p>

<?php foreach( get_the_category() as $category ): ?>
<div class=”category-name”><em>filed under <a href=”<?= get_category_link( $category->cat_ID ); ?>”><?= $category->name ?></a></em></div>
<?php endforeach; ?>

<p class=”post-excerpt”><?= excerpt(14); ?></p>

<a href=”<?= the_permalink(); ?>” class=”read-more”>CONTINUE READING</a>

<div class=”hr hr-gray”></div>

<ul class=”additional-posts”>
<?php elseif( $post_date == $previous_month && $semaphore == 1 ): ?>
<li><a href=”<?= get_the_permalink(); ?>”><?= the_title(); ?></a></li>
<?php endif; ?>

<?php endwhile;

// Reset Query
wp_reset_query();
?>
</ul>
</div> <!– /.collapse –>
</div> <!– /.month –>

</div> <!– /.post-archives –>

Read more here:: Collapsible menu on post sidebar only expands and does not collapse

Leave a Reply

Your email address will not be published. Required fields are marked *