I need to be able to display a custom field for my subcategories. I have a multi language website and need the categories translated. I use the en / es / ch for a language variable in the path.php (i just followed the wiki entry to multi language website)
I read in the thread that you can wrap the custom_field with the category tag from expression engine, but I was not able to get this working. Here is the code in questions. (in this case without the exp:weblog:categories tag since I am not sure how and where to put it)
{exp:category_id category_group="3" category_url_title="{segment_4}" parse="inward"}
{exp:child_categories parent="{category_id}" child_categories_sort_direction="asc" show_empty="yes" entries_sort_direction="asc" parse="inward"}
{child_category_start}
<li class="left-img left-img-2"><a href="http://{path=products/prod-list/{parent_category_url_title}/{child_category_url_title}"><img src="{child_category_image}" alt="{child_category_name} _title=" width="141" height="140" />{if country_code != "en"}{{country_code}_product-name}{if:else} {child_category_name}{/if}_</a></li>
{child_category_end}
{/exp:child_categories}
{/exp:category_id}
I used the following tags for testing: {exp:weblog:categories} {exp:weblog:category_heading} I tried to put these tags in all kinds of different lcoationgs within the child_category tag and I actually was able to get the custom field “_product-name” to parse and also add the language variable es or ch. HOWEVER, everytime I was able to get the field to parse and display the right translation, ALL the subcategories displayed, instead of just the 4 subcategory which belong to one parent category. I tried to add show=”{child_category_id}” or show=”{category_id}” to the exp:weblog:categories tag but I was not able to get it working right. I was hoping that I overlooked something and that you can give me a pointer. I am SO! close…
(ps: the if statement seems to work fine.. the english category title displays without a problem.. )
@Laisvunas
{country_code} is a global variable, yes. The custom fields are only {es_product-name} and {ch_product-name}. When global variable is en the regular category field will be displayed; {child_category_name}. If the global variable is es or ch, it should replace the {country_code} with either es or ch. So the code for the custom field looks like {{country_code}_product-name}
Like I said in my original post. I was able to get the country_code variable to parse the correct code and also was able to get the custom field to display correctly. I achieved that by wrapping exp:weblog:categories around the custom field.
When wrapping the custom field with category tag, I was NOT able to display the correct subcategories. All the subcategories displayed, or the two subcategories were repeated many times. The correct display should be something like - Parent Category Name (Fruit) – Child Category Name (Apricot) – Child Category Name (Cherry) – Child Category Name (Citrus)
The english works without a problem with the current code that I pasted in original post. Right now it’s just a matter of getting this custom category field to display!
Hi florian,
Try this code:
{exp:category_id category_group="3" category_url_title="{segment_4}" parse="inward"}
{exp:child_categories parent="{category_id}" child_categories_sort_direction="asc" show_empty="yes" entries_sort_direction="asc" parse="inward"}
{child_category_start}
<li class="left-img left-img-2"><a href="http://{path=products/prod-list/{parent_category_url_title}/{child_category_url_title}"><img src="{child_category_image}" alt="{child_category_name}_title=" width="141" height="140" />_{exp:weblog:categories weblog="my_weblog" style="linear" show="{child_category_id}"}_{if "{country_code}" == "es"}{es_product-name}{/if} _{if "{country_code}" == "ch"}{ch_product-name}{/if} _{if "{country_code}" != "es" AND "{country_code}" != "ch"}{child_category_name}{/if}_{exp:weblog:categories}__</a></li>
{child_category_end}
{/exp:child_categories}
{/exp:category_id}
1.) When I try to use your code - nothing displays for english language or spanish etc. (I did fix your line of code. changed it from {exp:weblog:categories} to {/exp:weblog:categories} )
2.) When I take out show=”{child_category_id}”, the correct english, spanish etc displays correctly, but the category name gets repeated 18 times. (I attached a screenshot to show this better. screenshot is called 1-no-child-cat-id.jpg)
3.) when I try to add show=”{category_id}”, the english language displays correctly, and the spanish etc languages display the parent-category-name for each supcategory. This seems odd to me. The links, and pictures etc all work fine, just not the category name. (I attached a screenshot to show this scenario better for the spanish language. its called 2-parent-id-spa.jpg)
would this help us narrowing down the issue? In my humble opinion the problem must be with the show parameter for the exp:categories tag. However, I am not sure how to get it corrected!
Hi kmgkid, {switch} variable is not supported. I’m not sure how much it is in demand. Cheers.
No Worries Laisvunas, I ended up using this, which was a suggestion by Ingmar
<?php if (({child_category_count}-1)%2) { echo "unit_box_right"; } else { echo "unit_box_left"; }?>
The thread that Ingmar posted the solution is here http://ellislab.com/forums/viewthread/82694/#416129
Hi florian,
You should at first get this code
{exp:weblog:categories weblog="my_weblog_short_name" style="linear" show="child_category_id_number"}
{if "{country_code}" == "es"}{es_product-name}{/if}
{if "{country_code}" == "ch"}{ch_product-name}{/if}
{if "{country_code}" != "es" AND "{country_code}" != "ch"}{child_category_name}{/if}
{/exp:weblog:categories}
working outside exp:child_categories tag, that is, in a blank template. When you will get it working, put it inside exp:child_categories tag.
This is really a great plugin, many thanks for the work you’ve shared. But I’m missing something very simple here. I’ve gone thru the thread, and don’t think I’ve missed the answer, so…
I’m just trying to use this on a category page, where I show the child categories and link. Works perfectly when I hard code the parent=”15”, but I need to dynamically get this. My url is …com/template_group/category/C15 But I can’t seem to get this to display. Here is what I’ve tried, with many variables:
{exp:weblog:categories weblog="weblog"}
{exp:child_categories parent="{category_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes"}
{child_category_start}
<a href="http://{path=directory/category}C{child_category_id}">{child_category_name}</a>
{child_category_description}
{child_category_end}
{/exp:child_categories}
{/exp:weblog:categories}
And that returns all children, for all categories. So how to get the parent= to come from the segment_3? I know it’s something simple I’m missing.
Hi simplyee,
Try to use {segment_3} global variable together with Find and Replace Plus plugin:
{exp:replace_plus parse="inward"}
{exp:child_categories parent="{replace_area find="C"}{segment_3}{/replace_area}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes"}
{child_category_start}
<a href="http://{path=directory/category}C{child_category_id}">{child_category_name}</a>
{child_category_description}
{child_category_end}
{/exp:child_categories}
{/exp:replace_plus}
With regards to {parent_category_children_count} I have the following Category structure -
Parent 1 – Child 1 – Child 2
Parent 2 – Child 1 – Child 2
I assigned 1 entry to one of the subcategories but both parents are reporting that they have a child with an entry.
Here is my code -
{exp:child_categories weblog="content_tutorials" parent="1|2" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no" entries_sort_by="date" entries_sort_direction="asc"}
{parent_category_start}
<h3><a href="http://">{parent_category_name} - {parent_category_children_count}</a></h3>
<div class="lessons">
to download or view a lesson plan select from the lessons below
{parent_category_end}
{child_category_start}
<h4><a href="http://">{child_category_name}</a></h4>
<div class="lessons_downloads">
{child_category_end}
{entries_wrapper_top_start}
<ul>
{entries_wrapper_top_end}
{entries_start}
<li>{title}<a href="http://">{title}</a></li>
{entries_end}
{entries_wrapper_bottom_start}
</ul>
</div> <!-- lessons_downloads -->
{entries_wrapper_bottom_end}
{parent_wrapper_bottom_start}
</div> <!-- lessons -->
{parent_wrapper_bottom_end}
{/exp:child_categories}
Now am I correct in thinking that if I set show_empty to no then the parent category shouldn’t show? Both my parent categories are showing.
Am I doing something wrong?
This plug in is great! I have a couple questions:
{exp:replace_plus parse="inward"}
{exp:child_categories parse="inward" parent="{replace_area find="C"}{segment_2}{/replace_area}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no"}
{parent_category_start}
<h2>FAQs: {parent_category_name}</h2>
{parent_category_end}
{child_category_start}
<h3>{child_category_name}</h3>
{child_category_end}
{entries_wrapper_top_start}<div id="faqentries">{entries_wrapper_top_end}
{entries_start}
<div class="question">{exp:single_field field="f_question" weblog="{my_weblog}" entry_id="{entry_id}" field_format="xhtml"}</div>
<div class="answer">{exp:single_field field="f_answer" weblog="{my_weblog}" entry_id="{entry_id}" field_format="xhtml"}</div>
{entries_end}
{entries_wrapper_bottom_start}</div>{entries_wrapper_bottom_end}
{/exp:child_categories}
{/exp:replace_plus}
My db question and answer fields are set to XHTML, but when I set the format the same in the single_field tags, it correctly renders my tags, but it is not correctly rendering lists – they are displaying as literal HTML tags (<ul><li>). If I set the format to raw, then it renders the lists correctly, but it ignores all of my paragraph tags. If I leave off the field_format param, it is the same as the xhtml format.
Any idea why the lists are not correctly rendered?
{exp:child_categories parse="inward" sibling="{segment_3}" parent="{replace_area find="C"}{segment_2}{/replace_area}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no"}
Thanks!
Just a heads up for those who would like to use conditionals inside of the variable pairs, for comparing to segment_n for example.
This will not work:
{if url_title == segment_3} class="current"{/if}
which is ok with typical entries
This however will:
{if "{url_title}" == "{segment_3}"} class="current"{/if}
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.