Let us modify our "tutorial.html
" template in the following way:
<BOUCLE_article(ARTICLES)>
#TITRE
</BOUCLE_article>
Here, we’ve removed the {id_article}
condition altogether. A word of caution, this loop can generate a very large page if your database contains a lot of articles; it is worth taking precautions by adding {0,10}
to limit the loop to the first 10 articles.
<BOUCLE_article(ARTICLES){0,10}>
And the result, simply calling http://yoursite.net/spip.php?page=tutorial
(no need for id_article
from now on, since this condition was removed from the template), the titles of the first 10 published articles are displayed, each on a separate line. From this example, you can see how you can produce the synopsis of a section. Now let us display the 10 most recent articles in this section:
<BOUCLE_article(ARTICLES){id_rubrique}{par date}{inverse}{0,10}>
<a href="#URL_ARTICLE">#TITRE</a><br />
</BOUCLE_article>
Let’s look through this code bit by bit:
- id_rubrique
: only includes the articles belonging to the id_rubrique
section (see below that this variable is defined in the context of our BOUCLE_article
);
- {par date}{inverse}
: sort by date starting with the most recent.
- {0,10}
: ... and take only the first 10 results.
- Lastly, the code <a href="#URL_ARTICLE">#TITRE</a>
will display not only the title of the article but also generate links to those articles.
All that remains is to call the template, while passing the context id_rubrique=1
:
http://yoursite.net/spip.php?page=tutorial&id_rubrique=1
[*]
The magic of SPIP lies in combining these types of functionality for more complex or specific results. If you already understand this point, you’re well on the road to great success!