The attached add-on files may be out of date. Please visit Devot-ee for the latest versions.
I would like to present to your attention a new plugin: Category Info. This plugin allows you to output info about certain category without specifying anything about weblog or entries.
PARAMETERS:
1) category_id - Required. Allows you to specify category id number.
2) site - Optional. Allows you to specify site id number.
3) invalid_input - Optional. Accepts two values: “alert” and “silence”. Default value is “silence”. If the value is “alert”, then in cases when the plugin has some problem with parameters, PHP alert is being shown; if the value is “silence”, then in cases when the plugin has some problem with parameters, it finishes its work without any alert being shown. Set this parameter to “alert” for development, and to “silence” - for deployment.
VARIABLES:
1) {cat_info_category_group_name}
2) {cat_info_category_group}
3) {cat_info_parent_category_id}
4) {cat_info_category_name}
5) {cat_info_category_url_title}
6) {cat_info_category_description}
7) {cat_info_category_image}
8) {cat_info_subcategories_number}
9) {cat_info_nonempty_subcategories_number}
Also the values of custom category fields can be retrieved using their names with “cat_info_” appended. E.g. if there is custom category field named “my_field”, its value can be outputted using variable {cat_info_my_field}.
Conditionals are supported.
EXAMPLE OF USAGE:
{exp:cat_info category_id="{segment_3}"}
{if cat_info_category_group=="3"}
Some code
{/if}
{if cat_info_category_group=="45"}
Some code
{/if}
{/exp:cat_info}
Will this accept a “C3” type segment as the category_id parameter?
No. If “C3” means “category having category id 3”, then you first should strip the letter “C”. To do this you can use my other plugin called “Find and Replace Plus”.
Hi,
I released version 1.2 of Category Info plugin.
New features:
1) “invalid_input” optional parameter. It accepts two values: “alert” and “silence”. Default value is “silence”. If the value is “alert”, then in cases when the plugin has some problem with parameters, PHP alert is being shown; if the value is “silence”, then in cases when the plugin has some problem with parameters, it finishes its work without any alert being shown. Set this parameter to “alert” for development, and to “silence” - for deployment.
2) variable {cat_info_nonempty_subcategories_number} - outputs number of non-empty subcategories.
3) support for custom category fields. Values of custom category fields can be retrieved using their names with “cat_info_” appended. E.g. if there is custom category field named “my_field”, its value can be outputted using variable {cat_info_my_field}.
Getting a PHP Notice error:
Notice: Undefined variable: conds2 in /nfs/c05/h01/mnt/71344/domains/mysc.org/html/mysccontrol/plugins/pi.cat_info.php on line 192
I wouldn’t normally care, except that having the error is interfering with some other parsing on the page somehow!
Hi Adrienne,
If error message is the only problem, you can easily suppress it bu using PHP error control operator. E.g.:
// Typical Example
$var = @some_function();
Right, except that it’s ALSO causing issues with parsing for the errors to be on. I did fix the problem, at least temporarily, by changing the display of errors to logged-in users via the EE control panel. but it might be a good idea to sort out WHY that notice is happening, for your next version! 😊
…oops, sorry, forgot about that. I’m a dork. :) Here’s a fairly minimal sample:
{exp:weblog:category_heading weblog="section_gallery"}
{embed="includes/.declarations"
pagetitle="
{if "{parent_id}" > 0}
{exp:cat_info category_id="{parent_id}"}
{cat_info_category_name}
{/exp:cat_info}
{/if}
"
}
{/exp:weblog:category_heading}
Great Plugin Laisvunas.
I made a few modifications to accept either the category_id or the category_url as a required parameter. Often we have the category_url from a segment (instead of the id). I also added a new output tag so that the category id would then be available for output if you input the category url.
{cat_info_category_id}
Hi dpdexter,
When I have category_url_title from the segment and need category_id, I convert category_url_title into category_id using Category Id plugin.
It is not very good to allow category_url_title to represent category since category_url_title does not allow to identify category uniquely (category_url_title is unique only within its category group).
Ah - good point. For our particular use case it worked beautifully because our project allows users to build categories dynamically on the front end and the category url title is unique because we were prepending the parent category url title to the new url title.
Thank you for the feedback. Lesson learned.
Best, David
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.