Hi,
I would like to present to your attention a new plugin: Entries Number. It allows to find number of entries posted into certain weblogs and/or into certain categories and/or having
certain url_title or entry_id.
The idea to write such plugin may seem strange: {exp:weblog:entries} tag has {total_results} variable, which can be used in conditionals, and if no_results conditional.
The problem is that in case you use no_results conditional, you cannot wrap {exp:weblog:entries} tag into a plugin. That is, the code as this
{exp:category_id category_group="3" category_url_title="segment_3" parse="inward"}
{exp:weblog:entries weblog="my_weblog" category="{category_id}"}
{if no_results}
No entry found!
{/if}
{/exp:weblog:entries}
{/exp:category_id}
will not work.
In order to be able to find number of entries and to use other plugins at the same time I have developed this plugin.
PARAMETERS:
1) category - Optional. Allows you to specify category id number
(the id number of each category is displayed in the Control Panel).
You can stack categories using pipe character to get entries
with any of those categories, e.g. category=“3|6|8”. Or use “not”
(with a space after it) to exclude categories, e.g. category=“not 4|5|7”.
2) weblog - Optional. Allows you to specify weblog name.
You can use the pipe character to get entries from any of those
weblogs, e.g. weblog=“weblog1|weblog2|weblog3”.
Or you can add the word “not” (with a space after it) to exclude weblogs,
e.g. weblog=“not weblog1|weblog2|weblog3”.
3) site - Optional. Allows you to specify site id number.
You can stack site id numbers using pipe character to get entries
from any of those sites, e.g. site=“1|3”. Or use “not”
(with a space after it) to exclude sites, e.g. site=“not 1|2”.
4) status - Optional. Allows you to specify status of entries.
You can stack statuses using pipe character to get entries
having any of those statuses, e.g. status=“open|draft”. Or use “not”
(with a space after it) to exclude statuses,
e.g. status=“not submitted|processing|closed”.
5) url_title - Optional. Allows you to specify url_title of an entry.
6) entry_id - Optional. Allows you to specify entry id number of an entry.
7) invalid_input - Optional. Accepts two values: “alert” and “silence”.
Default value is “silence”. If the value is “alert”, then in cases when some
parameter’s value is invalid plugin exits and PHP alert is being shown;
if the value is “silence”, then in cases when some parameter’s value
is invalid plugin finishes its work without any alert being shown.
Set this parameter to “alert” for development, and to “silence” - for deployment.
VARIABLES:
1) entries_number - outputs the number of entries which satisfy condition
entered in prameters.
EXAMPLE OF USAGE:
{exp:entries_number category="6" weblog="not weblog1|weblog4" site="1"}
{entries_number}
{/exp:entries_number}
The variable {entries_number} placed between {exp:entries_number} and {/exp:entries_number} tags
will output the number of entries which satisfy condition entered in prameters.
You can use {entries_number} variable in conditionals:
{exp:entries_number category="6" weblog="not weblog1|weblog4" site="1"}
{if entries_number==0}
Some code
{if:elseif entries_number==1}
Some other code
{if:else}
Yet another code
{/if}
{/exp:entries_number}
In contrast with “if no_results” conditional, which does not allow its parent tag {exp:weblog:entries} to be
wrapped in a plugin, contionals inside {exp:entries_number} does not interfere with outer plugins. That is, the code as this
{exp:category_id category_group="3" category_url_title="segment_3" parse="inward"}
{exp:entries_number weblog="my_weblog" category="{category_id}"}
{if entries_number==0}
No entry found!
{/if}
{/exp:entries_number}
{/exp:category_id}
will work properly.
Changelog:
-1.3 // Added “status” parameter.
-1.2 // Added “invalid_input” parameter.
-1.1 // Made possible to use {entries_number} variable both inside and outside conditional at the same time.
-1.0 // First release.
