Support Forums

The forums are closed and will be removed when we launch our new site.

Looking for support? You can access the support system via your account.

Dave Hall

Forum Replies Created

Viewing 1 post (of 1 total)
  • Dave Hall in reply to:
    year dropdown
    #276798

    I had this issue. I couldn’t find a solution here, so I created a very hacky javascript workaround that seems to work fine. Sharing it here in case anyone has a similar need to have a yearly dropdown and the developers don’t build it in.

    Here goes:

    1) Just after the filters in the theme template (index.php in my case) I have this:

    <li class=”moveme”>
    <select id=”years” class=”sf-input-select”>
    <option value=””>All Years</option>
    <?php wp_get_archives( array(
    ‘format’ => ‘option’,
    ‘type’ => ‘yearly’
    )); ?>
    </select>

    This creates a dropdown with all the years for which posts exist, with All Years added at the top.

    2) On the back end of the S&F plugin I added a Post Date field, set to date range, and a submit button.

    3) In my css stylesheet I hid the Post Date field and the submit button:

    .sf-field-submit,
    .sf-field-post_date,
    #primary > .moveme {
    display: none !important;
    }

    I’m also hiding the .moveme element when it first loads.

    4) Using jQuery/javascript I move the dropdown into the S&F form (where it becomes visible) on page load. When an option is selected, it populates the hidden Post Date fields with 1st Jan-31st Dec for the chosen year and clicks ‘submit’. The years dropdown gets reset when the form is reset.

    $(document).ready( function() {
    $(‘.moveme’).insertBefore(‘li.sf-field-post_date’).removeClass(‘moveme’);

    $(‘#years’).change(function() {
    var selectedValue = $(this).val();
    if (selectedValue == ” ) {
    $(‘.sf-datepicker’).val(”);
    } else {
    $(‘.sf-datepicker’).eq(0).val( ’01/01/’ + selectedValue.substr(selectedValue.length-5, 4 ));
    $(‘.sf-datepicker’).eq(1).val( ’31/12/’ + selectedValue.substr(selectedValue.length-5, 4 ));
    $(‘.searchandfilter .sf-field-submit input’).click();
    }
    });

    $(‘.search-filter-reset’).click(function() {
    $(‘#years’).val(”);
    });
    });

    NB. You’ll have to switch the order of 31/12 if you’re using American dates.

    Obviously this is sub-optimal, but hey, it works.

Viewing 1 post (of 1 total)