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 - Category Id.
This plugin allows you to find category id number.
PARAMETERS:
1) category_group - Required. Allows you to specify ID number of category group
(the ID number of each category group is displayed in the Control Panel).
Also you can use category group name as specified in Control Panel (since v1.6). Pipe character can be used inside the value of this parameter
to specify several category groups (since v1.6). In case you use pipe character, make sure category url titles are unique.
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}
Category Id2 is clone of Category Id. Having installed both Category Id and Category Id2 you can write the code as this:
{exp:category_id category_group="5" category_url_title="{segment_3}"}
{if category_id=="10"}
Some code
{if:else}
{exp:category_id2 category_group="5" category_url_title="{segment_4}"}
{if category_id2=="12"}
Some code
{/if}
{/exp:category_id2}
{/if}
{/exp:category_id}
Credits: Matt Stein who updated Category Id plugin to be compatible with EE 2.0.
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.
