The ability of etc_search to output search results to any area, makes the creation of dynamic menus rather easy. Let us see how to construct an archive search like this one:
We define two search queries on the admin-side of etc_search
: the first one (with id="1"
) is
SELECT DISTINCT DATE_FORMAT(Posted, '%m') month, MONTHNAME(Posted) monthname FROM textpattern WHERE {/^\d{4}$/::Posted LIKE '$0%'} AND Status=4 ORDER BY Posted
Its output form will be
<option value="<txp:search_term />-{month}">{monthname}</option>
The second search query (id="2"
) is
{?month::Posted::/^\d{4}\-\d{2}$/::{*} LIKE '$0%'} ORDER BY Posted
Now we create our live archive, plugging the output of the first query into the second one (with target
attribute). We use etc_query
(or rah_repeat
, or whatever) to generate year radio inputs, from 2012 to this year:
<txp:etc_search id="1" break="" target="#monthselect" live="-600" minlength="4" label="Year"> <txp:etc_query data="[2012..{?||strftime(%Y)}]"> <input type="radio" id="year-{?}" name="q" value="{?}" /> <label for="year-{?}">{?}</label> </txp:etc_query> </txp:etc_search>
<txp:etc_search id="2" label="Month"> <select name="month"> <option value="">Select</option> <optgroup id="monthselect"></optgroup> </select> </txp:etc_search>
Believe it or not, that’s all! And with the latest version, you can easily replace select inputs by checkboxes and enable muti-choice, if needed:
File(s)
- File: etc_query.txt [60.72 kB] (4257 downloads, ~29 per month)
- File: etc_search.txt [37.42 kB] (2095 downloads, ~15 per month)
- File: livesearch.jquery.js [1.97 kB] (1101 downloads, ~8 per month)