Loops & Logic 101
If you’ve seen or written any L&L markup, you’re undoubtedly familiar with the legendary Loop—the queen of queries and the tag to end all tags. The Loop tag is one of the most useful and important tags available in the L&L templating language. So important, in fact, that we named the plugin after it! And while its core concept is simple, mastering this tag requires having a good mental model of why and how it works. In this post, we’ll dive deep into what the Loop tag does and how you can use it as the foundation for any L&L template you could imagine.
What does the Loop tag do?
A loop can be thought of as an instruction that tells WordPress to look through the items in your site’s database to find every piece of content that matches a certain set of criteria. For each post that matches that criteria, the inner content of the loop runs once, allowing you to display the fields of each post or do any number of things using the other tags available in L&L. For a more detailed explanation of the Loop tag, take a look at our absolute beginner’s guide to Loops & Logic.
We should note that we didn’t invent the name; WordPress’s own theme development handbook refers to the PHP mechanism of getting post content as “The Loop”.
When should the Loop tag be used?
If you only need to work with fields from the current post (the post on which you’ve placed your Tangible Template), then there’s no need to use the Loop tag to get the content. Using tags like <Field title>
/ at the top level of your template (i.e. not nested inside other tags or loops) will get field data from the current post.
<h2>Recent posts by <Field author_full_name /></h2>
<ul>
<Loop type=post author="{Field author}" count=5 orderby=date order=desc>
<li>
<a href="{Field url}"><Field title /></a>
<Loop taxonomy=category post=current>
<If check="{Field name}" value=best-practices>
Useful tips!
</If>
</Loop>
</li>
</Loop>
</ul>
Autres mises en formes
lorem io ìnfo vert
lorem io 2 rouge
lorem io 3 jaune
ui bleu
ui gris
Insertion d'une image
Nous allons insérer une image du personnage principal de Trigun pour le plaisir :
voila une liste de code pour le plaisir :
blablabla
blablabla
blablabla
blablabla
voila une seconde liste :
blablabla
blablabla
blablabla
blablabla
blablabla
Apprend la mise en forme avec moi
Modify the docusaurus.config.js
file:
module.exports = {
themeConfig: {
navbar: {
items: [
{
type: 'docsVersionDropdown',
},
],
},
},
};
module.exports = {
themeConfig: {
navbar: {
items: [
{
type: 'docsVersionDropdown',
},
],
},
},
};
npm run docusaurus docs:version 1.0
JavaScript
<button onClick={() => alert('it s an alert')}>Click me!</button>
Bloc de code avec titre
module.exports = {
i18n: {
defaultLocale: 'en',
locales: ['en', 'fr'],
},
};
Test de la section déroulante
Details element example
Toggle me!
Nested toggle! Some surprise inside...
Test section déroulante
Markdown is declarative
Test triple choix
- Apple
- Orange
- Banana
Test triple choix
- Apple
- Orange
- Banana
module.exports = {
themeConfig: {
navbar: {
items: [
{
type: 'docsVersionDropdown',
},
],
},
},
};
module.exports = {
themeConfig: {
navbar: {
items: [
{
type: 'docsVersionDropdown',
},
],
},
},
};
module.exports = {
type: 'docsVersionDropdown',
},
Quotes
Markdown quotes are beautifully styled:
Easy to maintain open source documentation websites.
— Docusaurus