Group entries older than x years under common filter

212
February 24, 2018, at 08:16 AM

I'm having some trouble and would greatly appreciate any help. I have a list of dated entries that I'm filtering by year. There are buttons for each year. However, all entries older than 5 years should be grouped under a common filter/button ("older") and displayed when the button is clicked. The trouble is, of course, that the entries to be targeted change every year and I don't know how to compute finding the relevant entries.

First there is a row of "buttons":

<div id="years">
    <p id="filter-2018" class="button filter" data-year="2018">
        2018
    </p>
    <p id="filter-2017" class="button filter" data-year="2017">
        2017
    </p>
    <p id="filter-2016" class="button filter" data-year="2016">
        2016
    </p>
    ... (list of years)
    <p id="older" class="button">
        older
    </p>
</div>

This is how the entries are set up:

<div id="content-left-dates">
    <a href="termine/tragedie.html">
        <div class="date-entry filter-2017">
            <p>
                2017/01 – 2017/03
            </p>
            <p>
                La Tragédie de Carmen
            </p>
        </div>
    </a>
    ... (repeat)
</div>

This is the jQuery of how I filter the entries, order the buttons and show/hide the entries for each year:

var $btns = $(".button").click(function () {
    $btns.filter(this);
});
var $wrapper = $('#years');
$wrapper.find('.filter').sort(function (a, b) {
    return +b.dataset.year - +a.dataset.year;
})
.appendTo($wrapper);
$('#years p').click(
    function () {
        var show = this.id;
        $('#content-left-dates > a > div.' + show).show();
        $('#content-left-dates > a > div:not(".' + show + '")').hide();
        return false;
    }
);

I only want to display the first 5 buttons and then add a button to display all entries older than 5 years. I have worked this out:

$('#years .filter:gt(4)').hide();
$('#older').appendTo($wrapper);

Now I am stuck with actually targeting the right entries. Can anybody help? Thanks a lot in advance!

Rent Charter Buses Company
READ ALSO
Ajax File Uploading

Ajax File Uploading

Im trying to submit a form that has a file input via ajaxI have a few important things that need to happen

226
Jquery to detect mobile and show code based upn conditions

Jquery to detect mobile and show code based upn conditions

I am trying to run a code in a single page which is a html page that if the website is opening in mobile or desktop, i found this tutorial but not sure how to use it

159
Increment and decrement buttons

Increment and decrement buttons

I am novice in jQuery but trying to learn something very basicI am just trying to build up auto increment/decrement input fields like this:

215
Using Haskell&#39;s GHCI through a Java Program

Using Haskell's GHCI through a Java Program

What I would like to do is wrap my Java program around the GHCIIn my mind it should work like this:

179