Submitted : {par ...}

**SPIP**

# Article submitted

The article "** {par ...}**
(https://www.spip.net/ecrire/?exec=article&id_article=6376)" is submitted
for publication. on Wednesday 7 October 2020.

* * *

## {par ...}

Wednesday 7 October 2020 , by [jack](.././?page=auteur&id_auteur=593&) ,
[tcharlss](.././?page=auteur&id_auteur=6944&)

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

## Table of contents

* Sort by number
* Sort by lang and alphabetical order
* Sorting using to several field
* Order dynamically
* Random order
* Order the elements of a search by relevance

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[|Back to the table of contents](#s-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 num `***`field`***`}`**.
For instance, to sort according to title numerical prefix, `{par num
titre}` will display the item in the ascending order of their titles
numerical prefix, starting, if any, by the prefixless 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
juillet 1789`» between «`10. Something`» et «`20. Something else`».
2. when the prefixes start by `` (zero), `{par num titre}` will order 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 lang and alphabetical order[|Back to the table of
contents](#s-Sort-by-lang-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 to several field[|Back to the table of
contents](#s-Sorting-using-to-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}`
(https://www.spip.net/ecrire/?exec=article&id_article=6616) applies only to
the sorting criterion placed just before. Thus `{par date} {par titre}
{inverse}` will apply the reverse sort **only** on the field `titre` (*from
Z to A*), the `date` keeping its default sort (*from oldest to newest*)

This is why we introduced the notation **`{!par ...}`** which inverts *a*
sorting criterion in particular. For example: `{!by date} {by title
number}` orders 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}` orders the results by descending date
(*from the most recent to the oldest*) then by descending number for titles
with the same date; this writing 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 writing according to the results you
expect.

## Order dynamically[|Back to the table of contents](#s-Order-dynamically)

The criterion `{par ...}` also accepts dynamically specified SQL field
names, such as `#ENV`. For example: `{par #ENV{variable}}` will order on
the value of "*variable*" passed in 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}`
(https://www.spip.net/ecrire/?exec=article&id_article=6588).

## Random order[|Back to the table of contents](#s-Random-order)

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

## Order the elements of a search by relevance[|Back to the table of
contents](#s-Order-the-elements-of-a-search-by-relevance)

In order to classify the results of a search form
(https://www.spip.net/ecrire/?exec=article&id_article=2218) by relevance,
we will use the criterion `{par points} {inverse}` ; a simple `{par points}
` ordering the results from the smallest to the largest relevance.

**P.S.**
See also the `{inverse}`
(https://www.spip.net/ecrire/?exec=article&id_article=6616) criteria

[1] The 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*

— Sent by SPIP (https://www.spip.net/)

rubon199-7e493.jpg