Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2012-09-04 12:39:53

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

Limiting File Download List Items to Recent Years

How could I go about restricting <txp:file_download_list /> to show only files uploaded this current year and last year so that on 1 Jan next year everything rolls over to show the new current year’s and last year’s items.

To complicate things a wee bit, the site is on a server in the USA (Chicago) but the site is for an organisation based in Australia (Melbourne), though getting time offsets were covered here and here.

Offline

#2 2012-09-04 13:38:27

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Limiting File Download List Items to Recent Years

If you do not need pagination, something like this could work:

<txp:variable name="last_year"><txp:php>
	echo safe_strftime('%Y')-1;
</txp:php></txp:variable>

<txp:etc_query
  data='<txp:file_download_list form="my_files" sort="created desc" />'
  replace="div[@data-created<{?last_year}]"
/>

with my_files form like

<div data-created='<txp:file_download_created format="%Y" />'>
... file data ...
</div>

Offline

#3 2012-09-04 14:44:46

etc
Developer
Registered: 2010-11-11
Posts: 5,053
Website GitHub

Re: Limiting File Download List Items to Recent Years

Possibly a better option: select the ids of the fresh files:

<txp:variable name="fresh_files"><txp:etc_query
  data='SELECT id from txp_file WHERE YEAR(created) >= <txp:variable name="last_year" /> ORDER BY created desc'
  break=",">{id?}</txp:etc_query></txp:variable>

and use it as id attribute of <txp:file_download_list />.

Offline

#4 2012-09-05 03:29:58

joebaich
Member
From: DC Metro Area and elsewhere
Registered: 2006-09-24
Posts: 507
Website

Re: Limiting File Download List Items to Recent Years

Thank you very much, Oleg. I will try both options. I am grateful for your help.

Last edited by joebaich (2012-09-05 03:31:25)

Offline

Board footer

Powered by FluxBB