Hi,
I would like to present to your attention a new plugin - Category Id.
This plugin allows you to find category id number.
PARAMETERS:
1) category_group - (integer starting from 1). Required. Allows you to specify id number of category group
(the id number of each category group is displayed in the Control Panel).
2) category_url_title - (any string which consists from characters legal for use in url segment). Required.
Allows you to specify URL title of the category.
3) on_failure - (any string which consists from characters legal for use in ExpressionEngine’s tag parameter
values). Optional. Allows you to specify what {exp:category_id} tag will output in case category group or
category url title specified in parameters does not exist.
4) 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.
EXAMPLE OF USAGE:
If URL title of your category is “my_category” and id number of its category group is “5”
then you can use optionally either single tag as here
{exp:category_id category_group="5" category_url_title="my_category"}
or variable {category_id} within {exp:category_id}{/exp:category_id} tag pair as here
{exp:category_id category_group="5" category_url_title="my_category"}
{category_id}
{/exp:category_id}
Both will return id of the category which belongs to category group 5 and has URL title “my_category”.
Variable {category_id} within {exp:category_id}{/exp:category_id} tag pair is
more powerful because you can use its output as parameter of other tag. For such use
you must add parse=“inward” parameter to {exp:category_id} tag.
For example, code as this will work
{exp:category_id category_group="5" category_url_title="{segment_3}" parse="inward"}
{exp:weblog:category_archive weblog="my_weblog" show="{category_id}"}
Some code
{/exp:weblog:category_archive}
{/exp:category_id}
If category group or category url title specified in parameters does not exist then the tag {exp:category_id}
by default will return nothing. In case ‘on_failure’ parameter was defined,
the tag will output what was specified as a value of this parameter.
Place this tag in any of your templates.
Any comments and suggestions appreciated.
Changelog:
-1.3 // Added invalid_input parameter.
-1.2 // Added on_failure parameter. Fixed PHP error message being displayed when single tag was used.
-1.1 // Fixed PHP error message being displayed when needed category id not found.
-1.0 // First release.
