We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Category Info

Development and Programming

Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

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}
       
Brent Cartier's avatar
Brent Cartier
87 posts
16 years ago
Brent Cartier's avatar Brent Cartier

Nice! Will this accept a “C3” type segment as the category_id parameter?

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas
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”.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi,

I released version 1.1 of Category Info plugin.

in this release a new variable - {cat_info_subcategories_number} - was added. It outputs the number of subcategories.

       
krew's avatar
krew
6 posts
16 years ago
krew's avatar krew

I just wanted to pass on my thanks for your great plugins. Both this and the category_id plugin have made my transition to EE a great success, and much smoother than expected. My regards.

       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

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}.

       
Adrienne L. Travis's avatar
Adrienne L. Travis
213 posts
about 16 years ago
Adrienne L. Travis's avatar Adrienne L. Travis

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!

       
Laisvunas's avatar
Laisvunas
879 posts
about 16 years ago
Laisvunas's avatar Laisvunas

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();
       
Adrienne L. Travis's avatar
Adrienne L. Travis
213 posts
about 16 years ago
Adrienne L. Travis's avatar Adrienne L. Travis

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! 😊

       
Laisvunas's avatar
Laisvunas
879 posts
about 16 years ago
Laisvunas's avatar Laisvunas

Of course I will try to fix it.

You will help to fix if you can provide a snippet of code which produces the error.

       
Adrienne L. Travis's avatar
Adrienne L. Travis
213 posts
about 16 years ago
Adrienne L. Travis's avatar Adrienne L. Travis

…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}
       
Laisvunas's avatar
Laisvunas
879 posts
about 16 years ago
Laisvunas's avatar Laisvunas

Hi Adrienne,

Grab the version 1.2.1 - I fixed the bug.

Thanks for reporting.

       
David Dexter's avatar
David Dexter
88 posts
15 years ago
David Dexter's avatar David Dexter

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}

       
Laisvunas's avatar
Laisvunas
879 posts
15 years ago
Laisvunas's avatar Laisvunas

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).

       
David Dexter's avatar
David Dexter
88 posts
15 years ago
David Dexter's avatar David Dexter

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

       
1 2

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.