The attached add-on files may be out of date. Please visit Devot-ee for the latest versions.
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”. Also you can use “&” symbol to get entries each of which was posted into all specified categories, e.g. category=”3&6&8”. 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) author_id - Optional. Allows you to specify author id number. You can use the pipe character to get entries posted by any of those authors, e.g. author_id=”5|11|18”. Or you can add the word “not” (with a space after it) to exclude authors, e.g. author_id=”not 1|9”. 4) 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”. 5) 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”. 6) url_title - Optional. Allows you to specify url_title of an entry. 7) entry_id - Optional. Allows you to specify entry id number of an entry. 8) show_expired - Optional. Allows you to specify if you wish expired entries to be counted. If the value is “yes”, expired entries will be counted; if the value is “no”, expired entries will not be counted. Default value is “yes”. 9) 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. 10) required_field - Optional. Allows you to specify which custom field should not be emty. Pipe character is supported; “not” operator is not supported. E.g. if we have required_field=”custom_field1|custom_field2”, then only those entries will be counted which have at least one of these fields not empty.
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.
Entries Number2 is clone of Entries Number. Having installed both Entries Number and Entries Number2 you can write the code as this:
{exp:entries_number category="6" weblog="not weblog1|weblog4" site="1"}
{if entries_number==0}
Some code
{exp:entries_number2 category="9" weblog="weblog5|weblog8" site="1"}
{if entries_number2>0}
Some code
{/if}
{/exp:entries_number2}
Some code
{/if}
{/exp:entries_number}
Changelog:
-1.7 // Added “required_field” parameter. -1.6 // Added “author_id” parameter. -1.5 // Added “show_expired” parameter. -1.4 // Added possibility to use “&” in “category” parameter values. Fixed bug - entries number being equal to “0” when “status” parameter has a value consisting of two strings and space symbol between them. Fixed bug - entries posted into several categories being counted several times. -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.
Is there a way to use this in a calendar to show number of entries for each day?
Since plugin has no “date” parameter it cannot output number of entries posted on particular day.
It seems that you can use Query module for this purpose.
Hi,
I have released a version 1.2 of Entries Number plugin.
In this release parameter “invalid_input” was added. This parameter 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 the plugin finishes its work without any alert being shown. Set this parameter to “alert” for development, and to “silence” - for deployment.
Since the plugin does not do comprehensive validation of parameters’ values, you cannot be absolutely sure that in cases no alert was thrown the input was really valid.
If this plugin could do status as well, that would be fantastic. For example, I’m looking to find the count of entries of Category A, that have a status of “Draft”. Maybe I could combine this plugin with a query module query to get what I need?
This is relatively handy for outputting all entries, but I think a status filter would make it much more useful to me! Any suggestions on how else I could achieve what I’m after without having to resort to the too-heavy wegblog:entries tag would be appreciated, too.
Hi mdesign,
You made a very good suggestion.
I have uploaded a new release - 1.3 - of Entries number plugin in which “status” parameter is introduced. As with “status” parameter of exp:weblog:entries tag you can choose multiple statuses using a pipe character:
status="draft|reviewed|published"
Or exclude statuses using “not”
status="not submitted|processing|closed"
Grab the new version using the link in the first post and let me know if something goes wrong.
Hi Laisvunas,
Thanks for notifying me about this plugin. I’m have been unable to get the correct number of entries to appear with the following code:
{exp:entries_number weblog="weblog1" category="4&131;"}
{category_name} {entries_number}<<
{/exp:entries_number}
The results show the name of category “4” and the number of entries in category 4.
I’m trying to show the number of entries that belong to both category 4 AND 131.
Thanks
Hi Logtenberg,
I’m have been unable to get the correct number of entries to appear with the following code:The results show the name of category “4” and the number of entries in category 4. I’m trying to show the number of entries that belong to both category 4 AND 131.{exp:entries_number weblog="weblog1" category="4&131;"} {category_name} {entries_number}<< {/exp:entries_number}
If you need to show the number of entries that belong to both category 4 and 131 your code should be:
{exp:entries_number weblog="weblog1" category="4|131"}
{entries_number}
{/exp:entries_number}
I think I may have discovered a bug: If the status is made of two words, it doesn’t work.
I will check it.
Hi Laisvunas,
I think there is a misunderstanding regarding listing the number of entries belonging to 4 AND 131.
When I use the pipe character, it appears that the number of entries is the sum of all entries in category 4 and all entries in 131. What I instead need is the sum of entries that belong to both categories.
ie.
entry 1 (belongs to category 4, belongs to category 131) entry 2 (belongs to category 4 only) entry 3 (belong to category 131 only)
so if I had 3 entries, the entries_number would be “1” <– this is what I need. with the | character, the entries_number would be “3”
The reason I need this, is that I have 2 category groups - the first group is “type”, the second group is “location”. So I need a count of how many entries of a certain type are at a certain location.
Thanks Ryan
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.