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 it’s category group is “5”
then the code
{exp:category_id category_group="5" category_url_title="my_category"}
{category_id}
{/exp:category_id}
will return id of the category which belongs to category group 5 and has URL title “my_category”.
You can use output of {category_id} variable
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, then, in such case
the tag will output what was specified as value of this parameter.
Conditionals inside {exp:category_id} tag are supported. You can use conditionals to check if
category exists:
{exp:category_id category_group="5" category_url_title="{segment_3}"}
{if category_id!=""}
Some code
{if:else}
Another code
{/if}
{/exp:category_id}
Place this tag in any of your templates.
Any comments and suggestions appreciated.
Changelog:
-1.4 // Ditched support for single tag. Added support for conditionals.
-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.
