3

I have the following code within a template

<h1>{segment_2_category_name}</h1>
{exp:channel:categories show="{segment_2_category_id}" style="linear" parent_only="no"}

    {category_description}

    {if content-image}
        {exp:ce_img:pair src="{content-image}" max_width="328"}
         <img src="{made}" alt="{segment_2_category_name}">
        {/exp:ce_img:pair}
    {/if}
{/exp:channel:categories}

This displays the category description, category image etc. and it works fine for top level categories. However, it doesn't display anything but the title for sub-categories.

I have checked whether {segment_2_category_id} is being parsed by placing it inside the channel:categories tag and it outputs the ID as expected.

Does anyone have a clue why this might not be working?

UPDATE: Removing the ce_img tags makes no difference.

You can see the pages concerned here;

http://www.gillardcutting.com/applications/food-extrusion (top level cat)

http://www.gillardcutting.com/applications/dog-chews-dental-sticks (sub cat)

UPDATE

I've created a test template, cut back to the bare bones, in order to analyse the queries being run. The following query is executed;

SELECT LOWER(cat_url_title) AS cat_url_title, `cat_id`, `parent_id`, `group_id`, `cat_name`, `cat_description`, `cat_image`
FROM (`exp_categories`)
WHERE `site_id` =  '1'
AND LOWER(cat_url_title) IN ('applications', 'test', 'dog-chews-dental-sticks') 
AND `group_id` IN ('3', '2')  

If I run this query directly on the database then I get back the expected category information.

It's as if, for some reason, the stuff between the opening and closing exp:channel:categories tag pair just isn't being parsed IF I'm dealing with a sub-category.

This site is running on EE 2.4 (so next step is to try an update) and is using Structure as well as Low Seg2Cat but I don't think either of these is the issue as everything is working as it should except for this particular issue (and even then only with subcategories).

UPDATE

It appears that I must specify the parent category ID in order to get any child category information to display. This is despite my earlier finding regarding the query that is being executed.

Even adding parent_only="no" does not allow me to display child category data without also having the parent category included.

Is this an intentional feature or just some peculiarity/bug relating to the version of EE that this site is running?

Guess what? Another UPDATE - Workaround fix

I've figured out a workaround based on my findings, it's not perfect by any means and will break quite easily but will work OK in this particular instance.

Basically;

I include the seg2cat tag to get the current category's parent id and include this in the show parameter, this ensures we can display the child data.

To ONLY show the child data I then use a conditional to check the category being output in the loop against the seg2cat category id and only show it if it's the child category.

{exp:channel:categories show="{segment_2_category_parent_id}|{segment_2_category_id}" parent_only="no" style="linear"}
    {if '{category_id}' == '{segment_2_category_id}'}

        {category_description}

        {if content-image}
            {exp:ce_img:pair src="{content-image}" max_width="328"}
                <img src="{made}" alt="{segment_2_category_name}">
            {/exp:ce_img:pair}
        {/if}
    {/if}
{/exp:channel:categories}

If anyone can come up with a better way to do this I'd love to know!

  • What if you remove parent_only and hard code the Cat IDs, does it work as expected? – Nathan Pitman Dec 5 '13 at 12:51
  • Good call. The parent_only is only there because I was trying to make it work.... still doesn't work if I hardcode the category id – foamcow Dec 5 '13 at 13:30
  • Moving the code to an embed and passing it a category id doesn't work either. I mean, this should work right? – foamcow Dec 5 '13 at 13:39
  • This code should absolutely work. Can you post the debug output for the non-working query? – Anna_MediaGirl Dec 5 '13 at 18:56
  • Do you mean the resulting SQL from the output profiler or the template debug output? – foamcow Dec 10 '13 at 11:11
2

can you try this.. if you don't mind using GWcode Categories plugin.

<h1>{segment_2_category_name}</h1>
{exp:channel:entries channel="applications" limit="1"}
{exp:gwcode_categories cat_url_title="{segment_2}" style="linear"}
{category_description}
{if content-image}
{exp:ce_img:pair src="{content-image}" max_width="328"}
<img src="{made}" alt="{segment_2_category_name}">
{/exp:ce_img:pair}
{/if}
{/exp:gwcode_categories}
{/exp:channel:entries}
| improve this answer | |
  • No, this didn't work either. At best it just shows the field category field titles, repeated. This appears to be an issue with the fact these are sub-categories. If I move them to the top level then they display perfectly fine. – foamcow Dec 10 '13 at 11:08
1

I've figured out a workaround based on my findings, it's not perfect by any means and will break quite easily but will work OK in this particular instance.

Basically;

I include the seg2cat tag to get the current category's parent id and include this in the show parameter, this ensures we can display the child data.

To ONLY show the child data I then use a conditional to check the category being output in the loop against the seg2cat category id and only show it if it's the child category.

{exp:channel:categories show="{segment_2_category_parent_id}|{segment_2_category_id}" parent_only="no" style="linear"}
    {if '{category_id}' == '{segment_2_category_id}'}

        {category_description}

        {if content-image}
            {exp:ce_img:pair src="{content-image}" max_width="328"}
                <img src="{made}" alt="{segment_2_category_name}">
            {/exp:ce_img:pair}
        {/if}
    {/if}
{/exp:channel:categories}

If anyone can come up with a better way to do this I'd love to know!

| improve this answer | |
  • Thanks, I had to use this technique as well. This has to be a bug, but I appreciate your solution. – Thomas May 15 '14 at 19:13
0

What happens if you add a channel parameter to the tag? Does that change anything?

| improve this answer | |
  • Still doesn't work. – foamcow Dec 5 '13 at 17:21

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.