Default Tab & Filter For MixItUp

Quick Summary
- Set the load option's filter to .day1 in the mixitup() config so only day1 items show on first load and that tab appears active.
- Each item needs MixItUp's target class, mix by default, plus a filter class such as day1, which WordPress can print from post terms.
- controls.toggleDefault only matters with data-toggle controls and has no effect on regular data-filter buttons; define containerEl before the code runs.
MixItUp is a JavaScript library for filtering and sorting items in a grid. When the page loads, it shows all items by default. If your filter buttons work like tabs, for example one tab per event day, you usually want one tab selected and only its items visible from the start. The load option in the MixItUp config does that.
Run this in your JavaScript file after the MixItUp library has loaded and the container is in the page.
var mixer = mixitup(containerEl, {
animation: {
effects: 'fade scale(0.5)'
},
controls: {
toggleDefault: 'day1'
},
load: {
filter: '.day1'
}
});How it works
containerElis the element that holds your items, for example the result ofdocument.querySelector(). Define it before this code runs.load: { filter: '.day1' }is the key part. On first load, MixItUp shows only the items with the classday1, and the control withdata-filter=".day1"is marked as active, so it looks like the open tab.- Each item needs MixItUp’s target class (
mixby default) plus its filter class, such asday1orday2. In a WordPress loop you can print those classes from each post’s terms, as in printing custom taxonomy term slugs as CSS classes. To make another tab the default, change.day1to that tab’s class. animation.effectssets the transition: items fade and scale to half their size as they’re hidden, and back as they’re shown.controls.toggleDefaultonly matters when you use toggle controls (data-toggle). It sets the filter MixItUp falls back to when all toggles are switched off. With regulardata-filterbuttons it has no effect.
Related articles
- building filter items from taxonomy terms: the filter controls generated from WordPress terms
