When using the multiple {articles} tag, you will have a number of articles being output.

Articles Anywhere offers several values based on what place the article has in the list of articles. You can output the values via Data Tags, and you can also use these values in the If Structures.

This way you can conditionally output html/content/data based on these dynamic values, such as: the number of the article in the list, If this is the "first" or "last" article, if it's an "even" or "uneven" article, etc...

Note: If you use Pagination, the Numbers values will be based on the articles returned in the current page. To get the overall Numbers values regardless of pagination, you can append the respective Data Tag with a _no_pagination suffix.

Totals

The total value contains the number of the articles returned by the {articles} tag on the page.

If you use pagination, you can get the overall number of articles returned with the total_no_pagination value.

When you use the limit="..." attribute, to _ for instance _ only return 40 articles overall, then you might also want to know (and use) the total number of articles that would have been returned if there was no limit. You can get this value with the total_no_limit value.

Count

The count value contains the number of the article in that set of articles.
So the first article on the page will have a count value of 1. The seventh article on the page will have a count value of 7.

You can _ for example _ use this count tag to create id or class names. In the HTML/code view of the editor, you could place:

<div class="my_article_[count]">[title]</div>

This example will show the linked title and introtext of the first 3 articles, and only the linked title of the rest:

{articles category="Mice"}[link][title][/link]
{if count <= 3}[introtext]{/if}{/articles}

If you use pagination, you can get the overall number of the article with the count_no_pagination value.
So, if you show 10 articles per page, the first article in the second page will have a count value of 1, and a count_no_pagination value of 11.

Previous / Next

The previous value gives the number of the previous article in the list. This will return the number of the last article when the current is the first on the page.

The next value gives the number of the next article in the list. This will return the number of the first article (1) when the current is the last article on the page.

You can use these to create custom article navigation, or simple anchor links to the previous/next articles.
This is an html example of a blog page with previous/next links:

<p>{articles category="My Category}</p>
<h2><a href="/article_[count]"></a>[title]</h2>
<p>[text]</p>
<p><a href="#article_[previous]">previous</a> <a href="#article_[next]">next</a></p>
<p>{/articles}</p>

The has_next and has_previous values will return a true/false value based on whether there is a next/previous article on the page.
This means that has_previous will only be false for the first article on the page, and the has_next will only be false for the last article on the page.

If you use pagination, you can get the number of the overall previous and next articles with the previous_no_pagination and next_no_pagination values.
This means that has_previous_no_pagination will only be false for the first article on the first page, and the has_next_no_pagination will only be false for the last article on the last page.

Is First / Last

The is_first and is_last will return a true/false value based on whether the article is the first/last article on the page.

This example shows how to add a different class name for the first and last articles in the output (in html view):

<div class="my_article {if is_first}my_first_article{/if} {if is_last}my_last_article{/if}">

You can of course use this for other things as well, like conditionally showing extra data or html for the first and/or last article.

If you use pagination, you can get the overall first and last article with the is_first_no_pagination and is_last_no_pagination values.
So the is_last value will be true for every last article in each page, while the is_last_no_pagination value will only be true for the very last article in the last page.

Is Even / Uneven

The is_even and is_uneven values are handy for creating lists that have an alternating class. Like a "zebra_striped" table.

This example shows how to add a different class name for the even and uneven articles in the output (in html view):

<div class="my_article {if even}my_article_even{/if}{if uneven}my_article_uneven{/if}">

The same can be done with an else:

<div class="my_article {if even}my_article_even{else}my_article_uneven{/if}">

Or even shorter with the same result:

<div class="my_article my_article_{if uneven}un{/if}even">

You can of course use this for other things as well, like conditionally showing extra data or html for the even or uneven articles.

Every ...

The every_... values are useful to add extra html or a class name for every n. articles.

Let's say you want to create columns. Then you will need to add extra html or class names to mark the beginning or end of each row.
For this purpose you can use the every_... value.

This example shows how to add an extra closing and opening <div> after every 4th article in the output (in html view):

{if every_4}</div><div>{/if}

Columns

An even more flexible value is the is_..._of_... value.

Just some examples:

  • The is_1_of_3 value will be true for the 1st, 4th, 7th, etc article.
  • The is_3_of_3 value will be true for the 3rd, 6th, 9th, etc article.
  • And the is_2_of_5 value will be true for the 2nd, 7th, 12th, etc article.

This example shows how to add a different class name for every 2nd article when splitting the result in groups of 5:

<div class="my_article {if is_2_of_5}my_special_article{/if}">

See the If Structures section for more information on the {if} tags.

Page Numbers

If you use Pagination, you can output special pagination_based Number Values.

The per_page value contains the number of articles per page set to be returned.

The pages value contains the total number of pages generated by the results. And you can use the page value to return the number of the current page.

The previous_page value gives the number of the previous page. This will return the number of the last page when the current is the first page.
The next_page value gives the number of the next page. This will return the number of the first page (1) when the current is the last page.

The is_first_page and is_last_page will return a true/false value based on whether the current page is the first/last.

The has_next_page and has_previous_page values will return a true/false value based on whether there is a next/previous page.
This means that has_previous_page will only be false for the first page, and the has_next_page will only be false for the last page.

Calculations

Articles Anywhere can even do calculations on Number data tags such as [total], [total_no_limit],[total_no_pagination], [count], [count_no_pagination], [next] and [previous].

Here is how it works, using [count] as an example, where [count] is 10. You can use the following arithmetic operators:

[count]    = 10
[count-1]  = 9
[count+10] = 20
[count*3]  = 30
[count/2]  = 5