{par ...}

The {par ...} criterion defines the order in which a loop displays the items.

The {par ...} criterion defines the order in which a loop displays the items. For instance, articles can be sorted by their date of online publication: {par date}, their date of "earlier publishing": {par date_redac}, by their title: {par titre}, and so on.

Sort by number

It is possible to sort the items by the numerical prefix of one of the item’s fields (titre (the title), surtitre (the top title), ps (the postscript). [1]. The criterion syntax is as follow :
{par numfield}.
For instance, to sort according to the title numerical prefix, {par num titre} will display the item in the ascending order of their titles numerical prefix, starting, if any, by the prefix-less titles, which won’t be sorted.

Note :

  1. the {par num ...} criteria takes into account all the values starting by a number ; thus {par num surtitre} will place the top title «14 july 1789» between «10. Something» et «20. Something else».
  2. when the prefixes start by 0 (zero), {par num titre} will sort the prefixes including the greater amount of zeros prior to the prefixes with the lesser amount : 00000. Title…, 0000. Title…, 000. Title…, 0. Title…

Sort by language and alphabetical order

In a multilingual website, the {par multi ...} criterion allow you to sort alphabetically in each language separately ; for example: {par multi titre}. Without multi, the items would be sorted with all the languages mixed.

Sorting using several field

It is possible to sort item using several fields. {par field1, field2} indicates the sorting fields by priority: items will be sorted according to field1, than according to field2 when field1 have identical values. It is possible to indicate as many fields as necessary.
For instance {par date, titre} will sort the items by date (from the oldest to the most recent), and items having the same date will be sorted by their title (in alphabetical order).

It is also possible to use several criteria {par ...} in a loop.
For example: {par date} {par titre} is equivalent to {par date, titre}.

Warning:
When several sorting criteria are used, the criterion {inverse} applies only to the previous sorting criterion. Thus {par date} {par titre} {inverse} will apply the reverse sorting only on the field titre (from Z to A), the date keeping its default sorting (from oldest to newest)

This is why we introduced the syntax {!par ...} which inverts a particular sorting criterion. For example: {!par date} {par num titre} sorts the results by descending date (from the most recent to the oldest) then by ascending number for titles with the same date.
However: {!par date, num titre} sorts the results by descending date (from the most recent to the oldest) then by descending number for titles with the same date; this syntax is therefore equivalent to {! par date} {!par num titre} but is different from {par date, num titre} {inverse} (where {inverse} applies only on date).

So be careful to choose your criteria syntax according to the results you expect.

Sort dynamically

The criterion {par ...} also accepts dynamically specified SQL field names, such as #ENV. For example: {par #ENV{variable}} will sort on the value of "variable" passed in the url &variable=titre provided that this value is a SQL field of the table concerned by the loop.

So &variable=num titre will not work since no SQL field is named num titre. In this case it is better to use criterion {tri}.

Random order

It is possible to obtain a list sorted in a random order by using the criterion {par hasard}.

Order the elements of a search by relevance

In order to classify the results of a search form by relevance, we will use the criterion {par points} {inverse} ; a simple {par points} ordering the results from the smallest to the largest relevance.

Background

SPIP 4.0

From SPIP 4.0 onwards, the {par num xxx} criterion automatically integrates the {by sinum xxx} criterion before it. So in (ARTICLES){par num titre}, articles without numbers (or with the number 0) come after articles with a number.

In other words, it behaves like the {by sinum xxx, num xxx} script used in SPIP 3.2.

Consequently, titles containing 0. Title or 000. Title (all zeros) are now displayed after titles with numbers.

SPIP 3.2

From SPIP 3.2 onwards, the {by sinum xxx} criterion is used to place items with numbers before those without numbers. {par sinum xxx, num xxx} is therefore used to sort by number, placing items without numbers after those with numbers (unlike {par num xxx} only).

To have numbered items before those without numbers, you need to use the {par sinum field_name} criterion. This criterion places the numbered elements before the non-numbered ones, but it does not sort the elements within these 2 groups. It must therefore be used in conjunction with another sort criterion.

Example: {par sinum titre, num titre, titre} will put the unnumbered items at the end of the list, then sort within these 2 groups by title number and title.

See also the {inverse} criteria

Footnotes

[1The numerical prefix syntax is as follow :
a number, followed by a dot or a closing parenthesis, followed by a space.
examples :
015.A title
51)Another title

Author jack, tcharlss Published : Updated : 21/07/23

Translations : English, français, Nederlands