|
| 1 | +--- |
| 2 | +layout: document |
| 3 | +category: Tags |
| 4 | +published: false |
| 5 | +title: Items count |
| 6 | +description: The items_count tag is a single tag that returns the number of items (articles, images, etc) returned by list tags. |
| 7 | +tags: |
| 8 | + - Search tags |
| 9 | +--- |
| 10 | + |
| 11 | +# Items count |
| 12 | + |
| 13 | +**Contents** |
| 14 | + |
| 15 | +* Table of contents |
| 16 | +{:toc} |
| 17 | + |
| 18 | +## Syntax |
| 19 | + |
| 20 | +~~~ html |
| 21 | +<txp:items_count /> |
| 22 | +~~~ |
| 23 | + |
| 24 | +The **items_count** tag is a *single* tag that returns the number of (live) articles returned by an article tag. |
| 25 | + |
| 26 | +* Wrap with [if_search](/tags/if_search) tags to count search results. |
| 27 | +* Use in a regular article list page by wrapping with [if_article_list](/tags/if_article_list) to count articles in that section. |
| 28 | +* Use on the front (default) page to count the number of articles in sections with __On default page__ set to Yes. |
| 29 | + |
| 30 | +## Attributes |
| 31 | + |
| 32 | +Tag will accept the following attributes (**case-sensitive**) as well as the {% include atts-global-link.html %}: |
| 33 | + |
| 34 | +`text="text"` |
| 35 | +: Text to display with the number of matches. |
| 36 | +: **Default:** `articles found`. |
| 37 | + |
| 38 | +`pageby="integer"` |
| 39 | +: **Default:** `1`. |
| 40 | + |
| 41 | +## Examples |
| 42 | + |
| 43 | +### Example 1: Display number of search matches or articles in current section |
| 44 | + |
| 45 | +~~~ html |
| 46 | +<txp:if_search> |
| 47 | + <txp:items_count /> |
| 48 | +<txp:else /> |
| 49 | + <txp:if_article_list> |
| 50 | + <txp:items_count text="articles" /> |
| 51 | + </txp:if_article_list> |
| 52 | +</txp:if_search> |
| 53 | + |
| 54 | +<txp:article /> |
| 55 | +~~~ |
| 56 | + |
| 57 | +If the visitor is searching for articles, it will show the number of articles that matched the search term (e.g. 5) as follows: `5 articles found`. Otherwise, if Textpattern is displaying an article list, it will display the number of articles like this: `42 articles`. |
| 58 | + |
| 59 | +Note: The [if_search](/tags/if_search) conditional tag is required to recognize actual search results. Without it, the number of articles is returned by default. |
| 60 | +{: .alert-block .information} |
| 61 | + |
| 62 | +Other tags used: [article](/tags/article), [if_search](/tags/if_search), [if_article_list](/tags/if_article_list). |
| 63 | + |
| 64 | +### Example 2: Number of matches, using custom text |
| 65 | + |
| 66 | +~~~ html |
| 67 | +<txp:if_search_results> |
| 68 | + <txp:items_count text="hits" /> |
| 69 | +</txp:if_search_results> |
| 70 | +~~~ |
| 71 | + |
| 72 | +Displays the number of articles returned (e.g. 5) as follows: `5 hits`. |
| 73 | + |
| 74 | +Other tags used: [if_search_results](/tags/if_search_results). |
| 75 | + |
| 76 | +### Example 3: Regular (live) article count |
| 77 | + |
| 78 | +~~~ html |
| 79 | +<txp:if_article_list> |
| 80 | + <txp:items_count pageby="20" text="pages" /> |
| 81 | + <txp:article limit="20" /> |
| 82 | +</txp:if_article_list> |
| 83 | +~~~ |
| 84 | + |
| 85 | +Displays the number of pages in the current section, then displays articles as an article listing, 20 per page. |
| 86 | + |
| 87 | +Other tags used: [article](/tags/article), [if_article_list](/tags/if_article_list). |
0 commit comments