Articles Anywhere

show only if number of returned articles > 0

5 months 2 weeks ago #88923

Marc's Avatar Marc

Hi,
On a site, I have 26 tabs corresponding to an Alphabetical Index of articles in a given Category (see example herafter).

That code works... but of course it also shows the Tab even if there is no article starting with that particular letter.
So how can I make a condition, for example to add a Class to the Tab if there is no article for the Tab ?

Txs !

<p>{tab A}</p>
<p>{articles category="documentaires" articles="a*" ordering="title"}</p>
<p>{link}{title} <small><i>de {realisation}</i></small>{/link}</p>
<p>{/articles}</p>
<p>{tab B}</p>
<p>{articles category="documentaires" articles="b*" ordering="title"}</p>
<p>{link}{title} <small><i>de {realisation}</i></small>{/link}{/link}</p>
<p>{/articles}</p>

5 months 2 weeks ago #88924

Peter van Westen's Avatar Peter van Westen Admin

You can do:

<p>{articles category="documentaires" articles="a*" ordering="title"}</p>
<p>{if first}{tab A}{/if}</p>
...
<p>{/articles}</p>
<p>{tab B}</p>
<p>{articles category="documentaires" articles="b*" ordering="title"}</p>
<p>{if first}{tab B}{/if}</p>
...
<p>{/articles}</p>

Make sure the Articles Anywhere plugin is ordered before Tabs.

5 months 2 weeks ago #88925

Marc's Avatar Marc

would you believe it ?
it works ! 😎

txs again Peter

PS : if you have any suggestion to avoid repeating this 26 times, I will take it
(well, I have done it manually already, just out of curiosity for such needs)

5 months 2 weeks ago #88926

Peter van Westen's Avatar Peter van Westen Admin

You could make it a dynamic snippet or ReReplacer replacement.
Or use php (through Sourcerer) to loop through the alphabet and output the code.
Also with these approaches, the plugin ordering is pretty important.

5 months 2 weeks ago #88928

Peter van Westen's Avatar Peter van Westen Admin

With the Snippets approach, you could have a snippet output the block for a passed along letter. So in your content you could have:

{snippet documentaires|A}
{snippet documentaires|B}
{snippet documentaires|C}
...

5 months 2 weeks ago #88930

Marc's Avatar Marc

yep, the rereplacer/snippet approach is nice
at least, everytime I improve on the articles anywhere output, I only have to make it once 😜

Txs again and again Peter 🙂