I guess, we should create the filter with years correctly.
So let's check template 'members/documents.php' and get
all distinct years consecutively from its pages (via publish date).
I know that there is this tag -
<cms:archives />, which shows time period (year, month, day) and displays number of pages in each period.
Obviously, if there are no pages in period, then it is skipped. It can be tried out with following code:
- Code: Select all
<cms:archives masterpage='members/documents.php' type='monthly' >
<cms:dump />
</cms:archives>
It displays something like that (note, how
k_archive_count shows number of pages in the
month starting with
k_archive_date and ending before
k_next_archive_date).
Once we understand how tag works, let's make it
'yearly' for our purpose.
Output would be similar to following:
This way we can see the years of our pages by
k_archive_date. Format is
'Y-m-d', and to get only year it's necessary to convert it with
'Y' format, using
<cms:date /> tag -
- Code: Select all
<cms:date date=k_archive_date format='Y' />
What we want to achieve - submitted form should send to backend 2 dates - starting date and ending date. We have both, so let's assign a special value to each year - like
year =
start date # stop date,
sample: 2016 = 2016-01-01 # 2017-01-01.
So,
frm_year will have 2 dates and we can split it to feed our listing.
k_success block in the form would split it:
- Code: Select all
<cms:if frm_years!='-' >
<cms:each var=frm_years sep='#' >
<cms:if k_count='0' ><cms:set start_date = item scope='global' />
<cms:else_if k_count='1' /><cms:set end_date = item scope='global' />
</cms:if>
</cms:each>
</cms:if>
Now, listing will be changed very slightly:
<cms:pages masterpage='members/documents.php' custom_field=my_search_str order='asc' paginate='1' limit='20' start_on=start_date stop_before=end_date >
If year is not selected and variables
start_date /
end_date do not exist, listing will ignore empty values and show without year constraint.
So, finally, modify your input dropdown for years. It was like this:
- Code: Select all
<div>
<label>Year:</label><br />
<cms:input type="dropdown"
opt_values="All=- | <cms:pages masterpage='members/years.php' order='asc'><cms:show year /><cms:if k_paginated_bottom='0' >|</cms:if></cms:pages>"
opt_selected='All'
name="years" id="years" />
</div>
And we can change it to display only existing years, as planned.
- Code: Select all
<div>
<label>Year:</label><br />
<cms:input type="dropdown"
opt_values="All=- | <cms:archives masterpage='members/documents.php' type='yearly' ><cms:date date=k_archive_date format='Y' /> = <cms:concat k_archive_date ' # ' k_next_archive_date />|</cms:archives>"
opt_selected='-'
name="years" id="years" />
</div>
Ask any questions.