WordPress + Twig (Timber) – Showing current category in category dropdown

I currently have a category dropdown filter set-up for my blog pages. This works to switch between the category pages, however, I am having difficulty getting the dropdown box to show the active category.

Here is what I have in my archive.php file

$context['categories'] = Timber::get_terms('category');

And here’s the function that shows the current category dropdown.

<form id="category-select" class="category-dropdown" action="{{site.url}}" method="get"> 
  <select name="cat" id="cat" class="cat-menu" onchange="return this.form.submit()">
     <option value="-1">Select a category</option>
        {% for cat in categories %}
          <option class="level-0" value="{{cat.id}}">{{cat.name}}</option>
        {% endfor %}
     <option value="0">View All</option>
  </select>
<noscript><input type="submit" value="View" /></noscript></form>

Does anyone have any guidance on how to this properly?

Read more here: WordPress + Twig (Timber) – Showing current category in category dropdown

Leave a Reply

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