Search
Other Articles Anywhere questions
Forum

counting the number of articles assigned to a tag

Seppi's Avatar Seppi
Hi Peter

Didn't find anything about this in the ressources (but maybe I'm thinking the wrong way, maybe even too far):

I need to show the introtext of a specific article only, if there are no articles assigned to a tag. I tried to achieve this with «count», which doesn't work (which is, because «count» refers to the currently loaded articles only, right?).
{articles tags="mytag"} 
  {if count < 1}
    {article id="999"}[introtext]{/article}
  {/if}
{/articles}

For some reasons I can't work with categories in this case an need to stick to tags. The problem is I need to show a message, when no articles are assigned to the tag.

Any hint or alternative idea?

Thank you.

Peter
Peter van Westen's Avatar Peter van Westen ADMIN
You can use the empty="..." attribute for this.
See: docs4.regularlabs.com/articlesanywhere/p...gs#output-when-empty
{articles tags="mytag" empty="{article id="999"}[introtext]{/article}" limit="1"}{/articles}

The reason your approach is not working is because what is inside the {articles}...{/articles} tags gets repeated for every article found.
If no articles are found, then whatever is between the tags doe not get output.
So there will never be an article with count=0.
Please post a rating at the Joomla! Extensions Directory
Seppi's Avatar Seppi
Hi Peter

Thank you for your feedback.

I was able to add the code to my website and the text is displayed when there are no items.

When items are present, a product image is displayed above the grid. This should not be the case.

Below you can see the code I inserted and the link to the website to see what I mean.
{articles limit="1" tags="Schnäppchen" empty="{article id="2127"}[introtext]{/article}"}{/articles}

Confidential information:
(hidden)


Do you know what I did wrong and how I can solve this problem?

Thank you.

Peter
Peter van Westen's Avatar Peter van Westen ADMIN
Ah, that is because of this:
If you place nothing between the opening and ending tags, the full article will be placed:
{article title="Shetland Sheepdog"}{/article}
As described here:
docs4.regularlabs.com/articlesanywhere/data-tags/overview

To have 'nothing' be output, just place a space or an empty div tag or something between the {articles} tags.
Please post a rating at the Joomla! Extensions Directory
Seppi's Avatar Seppi
Hello Peter

I was able to solve the problem by inserting a space.

Thanks for your help.

Peter
Peter van Westen's Avatar Peter van Westen ADMIN
Great 🙂
Please post a rating at the Joomla! Extensions Directory
You can only post on the extension support forum if you have an active subscription and you log in

Buy a Pro subscription