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

Development and Programming

hothousegraphix's avatar
hothousegraphix
851 posts
16 years ago
hothousegraphix's avatar hothousegraphix
CP Home › Admin › Weblog Administration › Global Weblog Preferences
Automatically Convert High ASCII Text to Entities > NO!

It’s amazing how things work when you have them set in a way that will allow what you want.

Thank you for your tips. I really do appreciate the assistance.

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

Hello Laisvunas.

Is there any possibility to add a way to retrieve category custom fields in a next release? To support conditional variables would be very handy too.

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

Hi Michel,

Although Child Categories plugin cannot handle custom category fields natively, you can display them by using this plugin together with exp:weblog:categories tag.

Also there is possibility to use variables of Child Categories plugin in conditionals

The code would be as follows:

{exp:child_categories parent="18|29" entries_sort_by="date" entries_sort_direction="asc" entries_limit="3" site="1" parse="inward"}

  {parent_category_start}
  <h1><a href="http://{homepage}/category/{parent_category_url_title}/">{parent_category_name}</a></h1>
  {parent_category_end}

  {child_category_start}
  <h2><a href="http://{homepage}/category/{child_category_url_title}/">{child_category_name}</a></h2>
{if "{child_category_description}"!=""}{child_category_description}{if:else}No description found{/if}
  {child_category_end}


  {entries_start}
<a href="http://{weblog_url}{url_title}/">{title}</a>

{exp:weblog:categories show="{child_category_id}" weblog="{weblog_short_name}"}
{my_category_custom_field}
{/exp:weblog:categories}
  {entries_end}

  {/exp:child_categories}
       
michelG's avatar
michelG
32 posts
16 years ago
michelG's avatar michelG

Thanks.

  • Conditional variables: right! Just did a stupid coding mistake. :red:

  • Category custom field: Hmmm… In the following code, the value of the category custom field ({sitemap_template}) that is retrieved is the one of the parent, not the one of the child. I use it in the child’s URL to define what template should be used.

<ul>
{exp:weblog:entries weblog="{my_weblog}"}
{categories}
{exp:child_categories parent="{category_id}" child_categories_sort_by="custom" show_empty="yes"}
{child_category_start}
<li><a href="/index.php/{sitemap_template}/c/{child_category_url_title}">{child_category_name}</a>
{if "{child_category_description}"}
{child_category_description}{/if}</li>
{child_category_end}
{/exp:child_categories}
{/categories}
{/exp:weblog:entries}
</ul>
       
Adrienne L. Travis's avatar
Adrienne L. Travis
213 posts
16 years ago
Adrienne L. Travis's avatar Adrienne L. Travis

Would you by any chance be willing and able to make the entry_id of the given entry (as well as the title and url_title) available inside the {entries_start}/{entries_end} loop?

I just had to resort to an annoying custom query INSIDE the child_categories loop in order to get around the lack of this.

Thanks!

       
Ryan Blaind's avatar
Ryan Blaind
168 posts
16 years ago
Ryan Blaind's avatar Ryan Blaind

Hey Laisvunas,

I just wanted to run this by you to see if you had some insight on how I could do this differently.. I have used the solution you posted a few pages back that incorporates the category_id and EntryData plugins to display a list of entries organized by subcategory. Here is my template code:

<?
                    $count=0;
                    $opt = 'supplier-left|supplier-right';
                    $sopt = @explode("|", $opt);
                    ?>
                    {exp:category_id category_group="2" category_url_title="{segment_3}" parse="inward"}
                    {exp:child_categories parent="{category_id}" parse="inward" status="open" child_categories_sort_by="name" child_categories_sort_direction="asc" show_empty="no" entries_sort_by="title" entries_sort_direction="asc"}

                    {parent_category_start}
                    <h3>{parent_category_name}</h3>
                    {parent_category_end}

                    {child_category_start}
                    <div class="<? echo $sopt[($count + count($sopt)) % count($sopt)]; $count++; ?>">{!-- Opening part of the code which wrap child category --}
                    <h6>{child_category_name}</h6>
                    {child_category_end}

                    {entries_start}
                    <ul>
                    <li>
                        <strong>{title}</strong>
                        {exp:entrydata:field field="supplier-url" weblog="suppliers" url_title="{url_title}" field_format="xhtml"}
                        {exp:entrydata:field field="supplier-description" weblog="suppliers" url_title="{url_title}" field_format="xhtml"}
                    </li>
                    </ul>
                    {entries_end}

                    {child_wrapper_bottom_start}
                    </div>{!-- Closing part of the code which wrap child category --}
                    {child_wrapper_bottom_end}

                    {/exp:child_categories}
                    {/exp:category_id}

As you may note, I am using some php to get a pseudo “switch” effect for my <div> tags.

My question is this, is there any way to check if a field has any data contained in it before outputting it with the entrydata plugin? Or would there be a way to get this. Basically using the field_format=”xhtml” allows my fields to be wrapped in nice paragraph tags, and automatically changes the urls to proper anchor tags. However I would actually prefer to check if the fields contain anything before outputting anything at all. Something similar to how you would do it in a normal entries tag:

{if supplier-url != ""}<a href="http://{supplier-url/">{supplier-url}</a>{/if}

something along those lines.

Any ideas?

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

Hi,

@alienne I will add entry_id variable in the next release of Child Categories plugin.

@they inspire There is an easy way to check if single tag has some output. The code would be as follows:

{if "{exp:entrydata:field field="supplier-url" weblog="suppliers" url_title="{url_title}" field_format="xhtml"}" != ""}

Some code

{/if}
       
Adrienne L. Travis's avatar
Adrienne L. Travis
213 posts
16 years ago
Adrienne L. Travis's avatar Adrienne L. Travis

Laisvunas,

Not to push, but just so i can work around the idea – any idea when the next release will be? Are we talking days or weeks or what?

       
Ryan Blaind's avatar
Ryan Blaind
168 posts
16 years ago
Ryan Blaind's avatar Ryan Blaind

Thanks Laisvunas, cheers!

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

Hi alienne,

Grab the version 1.5.1. In it I implemented entry_id variable which can be used inside {entries_start}{entries_end} variable pair.

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

Oh, kick ASS. Thank you so much, Laisvunas! You’ve solved my problem!

       
bene's avatar
bene
20 posts
16 years ago
bene's avatar bene

Hello,

first of all great plugin, a mandatory one for all our future projects! A bit strange that it is not built-in in EE in the first place, but luckily there are people like you. Well done!

I have a question, this is the category structure of our product catalogue: - Category 1 —- subcat 1.1 ———product 1.1.1 ———product 1.1.2 ———product 1.1.3 —- subcat 1.2 ———product 1.2.1 ———product 1.2.2 —- subcat 1.3 ———product 1.3.1 ———product 1.3.2 ———product 1.3.3 ———product 1.3.4 - Category 2 (similar) - Category 3 ———product 3.1 ———product 3.2

This works fine to display eg. all subcategories and related products from category 1 using your plugin. Now the question, I would like that the link for eg product 1.1.1 would be something like /products/product_detail/Category_1/subcat1_1/product1_1_1 but I cannot seem to get this to work. Any ideas?

best regards, Tim.

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

Hi bene,

It seems that you should use {parent_category_url_title} and {child_category_url_title} variables. That is, your code should be like this:

{entries_start}
<a href="http://{weblog_url}{parent_category_url_title}/{child_category_url_title}/{url_title}/">{title}</a>
{entries_end}
       
bene's avatar
bene
20 posts
16 years ago
bene's avatar bene

Hello,

Thanks for your reply. Yes, that what I’ve tried, but the problem is then that in the linked page, the product detail is not resolved correctly… It appears (that’s is what support tolds me) that EE only is capable of resolving the correct entry when only 1 category is supplied in the url, in other words:

/products/product_detail/Category_1/subcat1_1/product1_1_1 does not work /products/product_detail/subcat1_1/product1_1_1 does work.

Of course for SEO reasons this is not ideal… Any ideas?

thank you! Tim

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

Hi bene,

You can easily use category_url_title in any URL segment if you add

dynamic="off"

parameter in exp:weblog:entries tag.

In case your URL segments 1-5 are

/products/product_detail/Category_1/subcat1_1/product1_1_1

your code in products/product_detail template should be as follows:

{exp:weblog:entries weblog="my_weblog" category="{segment_4}" url_title="{segment_5}" dynamic="off"}

Some code

{/exp:weblog:entries}
       
First 6 7 8 9 10 Last

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.