SPIP

[ar] [ast] [bg] [br] [ca] [co] [cpf] [cs] [da] [de] [en] [eo] [es] [eu] [fa] [fon] [fr] [gl] [id] [it] [ja] [lb] [nl] [oc] [pl] [pt] [ro] [ru] [sk] [sv] [tr] [uk] [vi] [zh] Espace de traduction

Download

Managing Dates

April 2004 — updated on : November 2010

All the versions of this article:

SPIP 1.6 introduced a number of criteria and tags to improve the management of article dates. Below is a list of these features.


Displaying dates

-   #DATE is the date of online publication. It can be changed after the publication of an article or of a news item etc. The date of a section is that of the most recent item contained in the section.

-  #DATE_REDAC is the “date of earlier publishing”. It is available only for articles and can be changed as much as you like.

-  #DATE_MODIF First appearing in [SPIP 1.5], this the date of the latest modification of the article. More precisely, this is the date when the article was last opened in “edit” mode, whether it was actually changed or not. This tag is convenient in most cases, though not absolutely reliable. It can’t be modified unless you want to set it to “now”: then just open the article in “edit” mode.

-  #DATE_NOUVEAUTES [SPIP 1.6] displays the date when the latest news announcement was sent out.

Formatting dates

If no filter is used, the #DATE... tags are displayed in native MySQL format: "2001-12-01 03:25:02".

The filters: |annee, |mois, |jour, |heures, |minutes, |secondes, mais aussi |affdate, |date_relative, |nom_mois, |nom_jour, |saison, etc. can be applied to offer various different display formats. A complete list of filters which can be used to format the display of date tags is supplied in the article SPIP’s Filters.

Date context

[SPIP 1.6] provides all loops with a date context. If you’re inside such loops as (ARTICLES), (BREVES) or (RUBRIQUES), the date in question is the publication date of the article, of the news item or the latest modification date of the section.

If you insert a date tag (#DATE) outside any loops in a template, the date will be that of the current day — unless a date is passed in the page URL.

If a date is passed through the URL, then (for PHP versions above 3.0.12) it is analysed through strtotime: thus ?date=2003, ?date=2003/01 will work, and so will date=-1year (a year ago), ?date=1march1970 (articles published on 1st March 1970), etc.

Date, Age and Relative Age criteria

For an explanation of how to sort items by date, see the article Criteria applicable to all loops.

The {age} criterion makes it possible to select articles according to the time span between their publication date and the current date. So, {age<30} will prevent articles older than 30 days from being displayed.

The {age_relatif} criterion (relative age) enables the comparison between the publication dates of two articles. If an article has just been selected in a loop, a second loop nested inside the first will be able to call those articles that were published in the week before the article was published — this is achieved through this code: {age_relatif<=7}{age_relatif>=0} — and so on.

The {age} and {age_relatif} criteria make it possible to differentiate between two articles published on the same day (this wasn’t possible until [SPIP 1.6]). Now you can make loops that fetch "previous" or "next" articles:

Caution! In spite of appearances, date comparisons are quite tricky to manage. Because of "vague dates" (e.g. an article published in a given month, without any specific day being stated) "age_relatif" can result in a zero value in one direction, but not in the other! Hence the asymmetry of the loops shown above: in one direction you’re requesting the "second most recent" {age_relatif>=0} article (because the most recent, on a loose comparison, can only be the article itself); in the other direction you’re requesting the oldest published article from among the ones that were, strictly speaking, published later.

The {jour_relatif} (relative day), {mois_relatif} (relative month) and {annee_relatif} (relative year) criteria work like age_relatif, but take into account dates rounded off to the day, month, and year respectively. For instance, if the URL contains the variable ?date=2003-01-01, the following loop will fetch "all the articles published in the month of March 2003".

Date of Earlier Publishing

If you’ve enabled the "Date of earlier publishing" option in the private area, most of the criteria presented above will work: just add _redac to the criterion. So, {age_redac>365} will display articles whose earlier publication date goes back to over a year. ("redac" means "writing", but in our case here: "publishing").

If a loop selects an article whose {date_redac} (date of earlier publication) is defined, an inner loop containing the {annee_relatif_redac=0} criterion will fetch articles whose earlier publication dates belong to the same year. (annee_relatif_redac translates as "relative year of publication").

An example of sorting articles by date on a site’s homepage

As an example, here’s how you can display all the articles of a site, sorted by publication months (usually coded in the sommaire.html) template:


Show the template of this page Site powered by SPIP | Translation area | Private area