-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
1 changed file
with
87 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,87 @@ | ||
--- | ||
layout: document | ||
category: Tags | ||
published: false | ||
title: Items count | ||
description: The items_count tag is a single tag that returns the number of items (articles, images, etc) returned by list tags. | ||
tags: | ||
- Search tags | ||
--- | ||
|
||
# Items count | ||
|
||
**Contents** | ||
|
||
* Table of contents | ||
{:toc} | ||
|
||
## Syntax | ||
|
||
~~~ html | ||
<txp:items_count /> | ||
~~~ | ||
|
||
The **items_count** tag is a *single* tag that returns the number of (live) articles returned by an article tag. | ||
|
||
* Wrap with [if_search](/tags/if_search) tags to count search results. | ||
* Use in a regular article list page by wrapping with [if_article_list](/tags/if_article_list) to count articles in that section. | ||
* Use on the front (default) page to count the number of articles in sections with __On default page__ set to Yes. | ||
|
||
## Attributes | ||
|
||
Tag will accept the following attributes (**case-sensitive**) as well as the {% include atts-global-link.html %}: | ||
|
||
`text="text"` | ||
: Text to display with the number of matches. | ||
: **Default:** `articles found`. | ||
|
||
`pageby="integer"` | ||
: **Default:** `1`. | ||
|
||
## Examples | ||
|
||
### Example 1: Display number of search matches or articles in current section | ||
|
||
~~~ html | ||
<txp:if_search> | ||
<txp:items_count /> | ||
<txp:else /> | ||
<txp:if_article_list> | ||
<txp:items_count text="articles" /> | ||
</txp:if_article_list> | ||
</txp:if_search> | ||
|
||
<txp:article /> | ||
~~~ | ||
|
||
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`. | ||
|
||
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. | ||
{: .alert-block .information} | ||
|
||
Other tags used: [article](/tags/article), [if_search](/tags/if_search), [if_article_list](/tags/if_article_list). | ||
|
||
### Example 2: Number of matches, using custom text | ||
|
||
~~~ html | ||
<txp:if_search_results> | ||
<txp:items_count text="hits" /> | ||
</txp:if_search_results> | ||
~~~ | ||
|
||
Displays the number of articles returned (e.g. 5) as follows: `5 hits`. | ||
|
||
Other tags used: [if_search_results](/tags/if_search_results). | ||
|
||
### Example 3: Regular (live) article count | ||
|
||
~~~ html | ||
<txp:if_article_list> | ||
<txp:items_count pageby="20" text="pages" /> | ||
<txp:article limit="20" /> | ||
</txp:if_article_list> | ||
~~~ | ||
|
||
Displays the number of pages in the current section, then displays articles as an article listing, 20 per page. | ||
|
||
Other tags used: [article](/tags/article), [if_article_list](/tags/if_article_list). |