Your sites Log in Sign up Menu

Group posts by date

Add the following snippet to your template’s script.js file. This assumes that all of your date elements have the class ‘date’. Feel free to adjust the value of dateSelector as needed.

1
2
3
4
5
6
7
8
9
10
11
12
// CSS selector which will match all the HTML elements containing a date
var dateSelector = '.date';
var dates = Array.from(document.querySelectorAll(dateSelector));

// Iterate over all the dates, hiding each date identical to its immediate predeccessor
dates.reduce(function(previousDate, el){
  if (previousDate && previousDate === el.innerHTML)
    el.style.display='none';
  return el.innerHTML;
}, '');