1

I am creating a faceted search using Low Search with the help of this post. I would like to include a list of years as a facet, too, but I only want years listed where there is an entry. For example, if I had an entries in 2004, 2005, 2007, 2010 and 2014, I'd want those to be what displays, but not 2006, 2008, 2009, etc. I'm stumped.

UPDATE APRIL 10: I've made some headway! Using Low's "Ranges" examples (scroll down to "Show entries for a given month"), I created my list of years. I'd really like to be able to generate the range dynamically so that I don't have to manually change the range every year. I created a low variable that outputs the year, but when I use it as the parameter value it creates a list of numbers starting from zero.

Here's my search code with the manual range that works:

{exp:low_search:form form_id="search" result_page="docs/index" query="{segment_2}"}

…other facets…

<fieldset>
    <legend>Year</legend>
    {exp:low_list:each items="2014|2003" as="year" range="yes"}
        <label>
        <input type="checkbox" name="year" value="{year}"{if low_search_year == year} checked{/if} />
            {year}
        </label>
    {/exp:low_list:each}
</fieldset>
<input type="submit" class="btn btn-small" value="Filter" />
{/exp:low_search:form}

And here's my search code with the low variable used in the range, which outputs a list of numbers starting at 0 (the variable when not used as a parameter value outputs just fine):

{exp:low_search:form form_id="search" result_page="docs/index" query="{segment_2}"}

…other facets…

<fieldset>
    <legend>Year</legend>
    {exp:low_list:each items="{exp:low_variables:single var='lv_var_doc_library_published_year' preparse:var_doc_library_sort='desc'}|2003" as="year" range="yes"}
        <label>
        <input type="checkbox" name="year" value="{year}"{if low_search_year == year} checked{/if} />
            {year}
        </label>
    {/exp:low_list:each}
</fieldset>
<input type="submit" class="btn btn-small" value="Filter" />
{/exp:low_search:form}

Does anybody have any ideas about how I can dynamically populate the parameter value?

0

How about using the Query module? Something like...

<select name="year">
  {exp:query sql="SELECT DISTINCT year FROM exp_channel_titles WHERE channel_id = X ORDER BY year DESC"}
    <option value="{year}">{year}</option>
  {/exp:query}
</select>

...where X is the channel ID you want to target.

| improve this answer | |
1

I would honestly consider using some PHP snippet's and PHP Parsing set to input. It'd come out much cleaner! This way your php can populate the attributes for you. I assume you want 2003 to current year right?

<?php
    $startYear = 2003;
    $endYear = intval(date("Y",time()));
?>

{exp:low_search:form form_id="search" result_page="docs/index" query="{segment_2}"}

    …other facets…

    <fieldset>
        <legend>Year</legend>
        {exp:low_list:each items="<?php echo $startYear . '|' . $endYear; ?>" as="year" range="yes"}
            <label>
                <input type="checkbox" name="year" value="{year}"{if low_search_year == year} checked{/if} />
                {year}
            </label>
        {/exp:low_list:each}
    </fieldset>

    <input type="submit" class="btn btn-small" value="Filter" />

{/exp:low_search:form}
| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.