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: Entry Categories

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.

Hi,

This plugin allows you to output info about categories the entry was posted into.

PARAMETERS:

1) entry_id - Required. Alows you to specify entry id number of the entry which categories you want to display.

2) site - Optional. Default value is “1”.

3) show - Optional. Allows you to specify category id number (the id number of each category is displayed in the Control Panel). You can stack categories using pipe character e.g. show=“3|6|8”. Or use “not” (with a space after it) to exclude categories, e.g. show=“not 4|5|7”.

4) show_group - Optional. show_group - Optional. Allows you to specify category group. You can stack group id numbers using pipe character show=“1|6|9”. Or use “not” (with a space after it) to exclude categories, e.g. show_group=“not 5|7|11”. Also you can use category group names as specified in control panel. You even can mix category group names and category group id numbers using pipe symbol.

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

VARIABLES:

1) {categories_number} - outtputs number of categories the entry was posted into.

2) {category_levels_number} - outputs number of levels of categories hierarchy.

The plugin supports huge number of variables of the types outlined below (level0 is the highest level of categories, level1 is the level of subcategories of highest level, etc.; category0 is the first category of certain level, category1 is the second category, etc.):

3) {level0_category0_cat_id}, {level0_category1_cat_id}, {level0_category2_cat_id} … {level1_category0_cat_id}, {level1_category1_cat_id}, {level1_category2_cat_id} … {level99_category99_cat_id}.

4) {level0_category0_cat_name}, {level0_category1_cat_name}, {level0_category2_cat_name} … {level1_category0_cat_name}, {level1_category1_cat_name}, {level1_category2_cat_name} … {level99_category99_cat_name}.

5) {level0_category0_cat_url_title}, {level0_category1_cat_url_title}, {level0_category2_cat_url_title} … {level1_category0_cat_url_title}, {level1_category1_cat_url_title}, {level1_category2_cat_url_title} … {level99_category99_cat_url_title}.

6) {level0_category0_parent_id}, {level0_category1_parent_id}, {level0_category2_parent_id} … {level1_category0_parent_id}, {level1_category1_parent_id}, {level1_category2_parent_id} … {level99_category99_parent_id}.

7) {level0_category0_group_id}, {level0_category1_group_id}, {level0_category2_group_id} … {level1_category0_group_id}, {level1_category1_group_id}, {level1_category2_group_id} … {level99_category99_group_id}.

8) {level0_category0_cat_description}, {level0_category1_cat_description}, {level0_category2_cat_description} … {level1_category0_cat_description}, {level1_category1_cat_description}, {level1_category2_cat_description} … {level99_category99_cat_description}.

9) {level0_category0_cat_image}, {level0_category1_cat_image}, {level0_category2_cat_image} … {level1_category0_cat_image}, {level1_category1_cat_image}, {level1_category2_cat_image} … {level99_category99_cat_image}.

10) {level0_category0_subcats_number}, {level0_category1_subcats_number}, {level0_category2_subcats_number} … {level1_category0_subcats_number}, {level1_category1_subcats_number}, {level1_category2_subcats_number} … {level99_category99_subcats_number}.

EXAMPLE OF USAGE:

{exp:entry_cats entry_id="3049" site="1"}

{if category_levels_number == 2}

{level0_category0_cat_name}, {level1_category0_cat_name}

{/if}

{/exp:entry_cats}
       
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 bug - variables present only in conditionals not being parsed - was fixed.

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

Hi,

I released version 1.2 of Entry Categories plugin.

In this release a piece of code was added which finds all parent categories which for some reason were not listed in exp_category_posts table among categories the entry was posted into (such thing happens!).

Everyone who uses this plugin is recommended to upgrade.

       
ron00nor's avatar
ron00nor
52 posts
16 years ago
ron00nor's avatar ron00nor

Hi Laisvunas,

What is the difference with the {weblog:entries} {categories} variable?

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

Hi ron00nor,

The difference with the {weblog:entries} {categories} variable consists in:

1) {weblog:entries} {categories} variable does not allow to differenciate between levels of categories;

2) {weblog:entries} {categories} variable does not allow to output subcategories number for each category.

       
michelG's avatar
michelG
32 posts
about 16 years ago
michelG's avatar michelG

Laisvunas, FYI, my server log has the following error for this plugin:

Undefined offset:  -1  on line 262
       
Laisvunas's avatar
Laisvunas
879 posts
about 16 years ago
Laisvunas's avatar Laisvunas

Hi Michel,

In order to debug it should be possible for me to reproduce the issue; so, provide the portion of your code which causes that error message.

       
michelG's avatar
michelG
32 posts
about 16 years ago
michelG's avatar michelG

Laisvunas, after doing some testing, it looks like just to have a minimal code like below will generate a PHP notice warning on the server.

Server: Linux/Apache, PHP 5.2.9

{exp:weblog:entries weblog="pages|welcome" limit="1" disable="categories|member_data|pagination|trackbacks"}
  {exp:entry_cats entry_id="{entry_id}" invalid_input="alert"}
    
    Entry ID: {entry_id}<br>
    Level0 ID: {level0_category0_cat_id}<br>
    Level0 Cat Name: {level0_category0_cat_name}<br>
    Level1 ID: {level1_category0_cat_id}<br>
    Level1 Cat Name: {level1_category0_cat_name}<br>
    Level2 ID: {level2_category0_cat_id}<br>
    Level2 Cat Name: {level2_category0_cat_name}<br>
    
  {/exp:entry_cats}
{/exp:weblog:entries}

The above gives me this server log notice:

PHP Notice:  Undefined offset: -1  on line 262

If one of the value cannot be retrieved:

PHP Notice:  Undefined index: 2  on line 386

Let me know if you need anything else.

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

Hi Michel,

checked your code and found that on my EE installation it works perfectly. I do not know what to suggest.

Perhaps it is worth to try to decouple exp:weblog:entries tag from exp:entry_cats tag, i.e. to try and see if the code

{exp:weblog:entries weblog="pages|welcome" limit="1" disable="categories|member_data|pagination|trackbacks"}
{entry_id}
{/exp:weblog:entries}

and the code

{exp:entry_cats entry_id="my_entry_id" invalid_input="alert"}
    
    Entry ID: {entry_id}<br>
    Level0 ID: {level0_category0_cat_id}<br>
    Level0 Cat Name: {level0_category0_cat_name}<br>
    Level1 ID: {level1_category0_cat_id}<br>
    Level1 Cat Name: {level1_category0_cat_name}<br>
    Level2 ID: {level2_category0_cat_id}<br>
    Level2 Cat Name: {level2_category0_cat_name}<br>
    
  {/exp:entry_cats}

works as expected.

       
michelG's avatar
michelG
32 posts
about 16 years ago
michelG's avatar michelG

I tried your suggestion. It is still giving the same errors.

My client’s EE installation is 1.6.7, Build 20090515. What is yours?

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

Mi Michel,

My EE installation is 1.6.8, Build 20090723.

I doubt that version and build might have any influence here.

       
michelG's avatar
michelG
32 posts
about 16 years ago
michelG's avatar michelG

Right. Upgraded to latest version/built. Didn’t make a difference. What about your server/PHP? This is what we run: Linux/Apache, PHP 5.2.9.

You understand that these errors only show on the server log, right? (Have you checked your server log?) These warnings do not influence how the plugin works.

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

Hi Michel,

Grab the version 1.2.1 - I fixed the bug.

Thanks for reporting.

       
michelG's avatar
michelG
32 posts
about 16 years ago
michelG's avatar michelG

Thank you very much, Laisvunas.

It works like a charm now.

       
Adrienne L. Travis's avatar
Adrienne L. Travis
213 posts
15 years ago
Adrienne L. Travis's avatar Adrienne L. Travis

Laisvunas,

I’m in dire need of this plugin accepting url_title instead of entry_id to identify the entry to grab. Is that at all do-able? I’m way stressed, trying to get a deadline done, and just realized that i can’t get this working as is.

It seems like it would bring it more in line with your other plugins, most of which will accept either identifier.

Thanks in advance for your time. 😊

Adrienne

       
1 2 3

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.