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

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

Hi guys,

Just uploaded version 1.2 of Child categories plugin. Grab it using the link in the first post in this thread.

New features added:

1) {parent_category_description} variable. It outputs description of parent category. Use this variable inside {parent_category_start}{parent_category_end}, {child_category_start}{child_category_end} and {entries_start}{entries_end} variable pairs.

2) {parent_category_image} variable. It outputs url of the image of parent category. Use this variable inside {parent_category_start}{parent_category_end}, {child_category_start}{child_category_end} and {entries_start}{entries_end} variable pairs.

3) {child_category_description} variable. It outputs description title of child category. Use this variable inside {child_category_start}{child_category_end} and {entries_start}{entries_end} variable pairs.

4) {child_category_image} variable. It outputs url of the image of child category. Use this variable inside {child_category_start}{child_category_end} and {entries_start}{entries_end} variable pairs.

5) {count} variable. It outputs order number of entry. Use this variable inside {entries_start}{entries_end} variable pair.

@ Paul Cripps

We really need to display child only catagories and to display: {category_name} {category_description} {category_id} {category_image} {count} {total_results}

{count} is now available for use. Concerning other variables in your list, use: instead of {category_name} - {parent_category_name} and {child_category_name}; instead of {category_description} - {parent_category_description} and {child_category_description}; instead of {category_id} - {parent_category_id} and {child_category_id}; instead of {category_image} - {parent_category_image} and {child_category_image}; instead of {total_results} - {entries_total}.

@ goodbytes

It seems that you need to use EntryData plugin together with Child Categories plugin. Using these plugins together you should add parse=”inward” parameter to {exp:child_categories} tag.

Try this code:

{exp:child_categories parse="inward" all_other_parameters="........."}
{entries_start}
{exp:entrydata:field field="menu_picture" weblog="{weblog_short_name}" url_title="{url_title}"}

{exp:entrydata:field field="menu_description" weblog="{weblog_short_name}" url_title="{url_title}"}

{exp:entrydata:field field="menu_price" weblog="{weblog_short_name}" url_title="{url_title}"}

{entries_end}
{exp:child_categories}

It should work if you will not make some mistake while coding this.

       
Paul Cripps (Nine Four)'s avatar
Paul Cripps (Nine Four)
104 posts
16 years ago
Paul Cripps (Nine Four)'s avatar Paul Cripps (Nine Four)

Laisvunas you are a star, I’ll give it a go now and let you know ho we go.

       
goodbytes's avatar
goodbytes
49 posts
16 years ago
goodbytes's avatar goodbytes

Thanks a lot Laisvunas!

The parse=”inward” did the job. My only concern remaining is the parent parameter which should also be filled in dynamically…

{exp:child_categories parse=”inward” parent=”6”

do you know how I can do this? My url looks like “food/percat/category/cold_food/”, and I need to have the parent ID dynamicallly filled in in your plugin to make it work completely…

any tips are appreciated!

Thanks again and keep up your good work

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

Hi goodbytes,

My url looks like “food/percat/category/cold_food/”, and I need to have the parent ID dynamicallly filled in in your plugin to make it work completely…

“cold_food” is url_title of parent category, isn’t it? If it is a case, then you can achieve what you want using Child Categories plugin together with another my plugin, Category Id. This plugin allows you to find category id after supplying category url_title. Do not forget to include parse=”inward” parameter into both {exp:child_categories} and {exp:category_id} tags.

The code should be approximately as follows:

{exp:category_id category_group="5" category_url_title="{segment_4}" parse="inward"}
{exp:child_categories parent="{category_id}" parse="inward" all_other_parameters="......"}
{entries_start}
{exp:entrydata:field field="menu_picture" weblog="{weblog_short_name}" url_title="{url_title}"}

{exp:entrydata:field field="menu_description" weblog="{weblog_short_name}" url_title="{url_title}"}

{exp:entrydata:field field="menu_price" weblog="{weblog_short_name}" url_title="{url_title}"}

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

Don’t be afraid if you get a sandwich made of two, three or even four nested plugins. It should work if you use parse=”inward” where needed.

       
goodbytes's avatar
goodbytes
49 posts
16 years ago
goodbytes's avatar goodbytes

Damn, so many plugins around that I didn’t even know of. Thanks again for your help! I got it to work!

       
odspi's avatar
odspi
29 posts
16 years ago
odspi's avatar odspi

It works as advertised, and I appreciate it. But I tried to format it by adding div sections around the variable pairs and they were removed from the final code:

<div> {child_category_start}

{child_category_start} </div> <ul> <entries-start> <entries-end> </ul>

Is there a remedy?

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

Hi odspi,

It is by intention that only that code is rendered which is included between variable pairs.

If you need to wrap the output of {child_category_start}{child_category_start} or {parent_category_start}{parent_category_end} variable pair with <div> tag, then this tag should be inside that variable pair:

{parent_category_start}
<div>
Some code
</div>
{parent_category_end}

{child_category_start}
<div>
Some code
</div>
{child_category_start}

If you need to wrap the output of {entries-start}{entries-end} variable pair with <ul> tag, then … it seems that this is not possible currently.

I will think about this problem.

One possible solution would be to introduce a new parameter, say “entries_wrapper”, which could accept such values as “div”, “ul”, etc., or even values with pipe character as “div|ul”.

Another solution would be to introduce two new variable pairs, say {entries_wrapper_top_start}{entries_wrapper_top_end} and {entries_wrapper_bottom_start}{entries_wrapper_bottom_end}.

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

Hi oldspi and all,

Just uploaded version 1.3 of Child Categories plugin. Grab it using the link in the first post of this thread.

New thing is introduction of two variable pairs:

{entries_wrapper_top_start}{entries_wrapper_top_end}

and

{entries_wrapper_bottom_start}{entries_wrapper_bottom_end}

The variable pair {entries_wrapper_top_start}{entries_wrapper_top_end} allows you to specify top part of the code with which you would like to wrap output of {entries_start}{entries_end} variable pair.

The variable pair {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} allows you to specify bottom part of the code with which you would like to wrap output of {entries_start}{entries_end} variable pair.

Exxample:

{exp:child_categories parent="18|29" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" entries_limit="3" site="1"}

{child_category_start}
<div class="my_category_div">
{child_category_name}
</div>
{child_category_end}

{entries_wrapper_top_start}
<div class="my_entries_div">
<ul class="my_entries_ul">
{entries_wrapper_top_end}

  {entries_start}
  <li><a href="http://{weblog_url}{url_title}/">{title}</a> Weblog: {weblog_name}, posted: {entry_date}</li>
  {entries_end}

{entries_wrapper_bottom_start}
</ul>
</div>
{entries_wrapper_bottom_end}

  {/exp:child_categories}

Such code will output something like this:

<div class="my_category_div">
some child_category_name
</div>

<div class="my_entries_div">
<ul class="my_entries_ul">
<li><a href="http://some_href">some_title_1</a> Weblog: some_weblog_name, posted: some_entry_date</li>
<li><a href="http://some_href">some_title_2</a> Weblog: some_weblog_name, posted: some_entry_date</li>
<li><a href="http://some_href">some_title_3</a> Weblog: some_weblog_name, posted: some_entry_date</li>
<li><a href="http://some_href">some_title_4</a> Weblog: some_weblog_name, posted: some_entry_date</li>
</ul>
</div>

<div class="my_entries_div">
<ul class="my_entries_ul">
<li><a href="http://some_href">some_title_1</a> Weblog: some_weblog_name, posted: some_entry_date</li>
<li><a href="http://some_href">some_title_2</a> Weblog: some_weblog_name, posted: some_entry_date</li>
<li><a href="http://some_href">some_title_3</a> Weblog: some_weblog_name, posted: some_entry_date</li>
</ul>
</div>

<div class="my_category_div">
some child_category_name
</div>

<div class="my_entries_div">
<ul class="my_entries_ul">
<li><a href="http://some_href">some_title_1</a> Weblog: some_weblog_name, posted: some_entry_date</li>
</ul>
</div>

Try it and give me to know if something goes wrong.

       
Paul Cripps (Nine Four)'s avatar
Paul Cripps (Nine Four)
104 posts
16 years ago
Paul Cripps (Nine Four)'s avatar Paul Cripps (Nine Four)

Laisvunas & oldspi I was getting the same, strange tags were being removed.

It was late friday and I wanted a beer by that point. I’ll test 1.3 and let you know how we get on.

Laisvunas again, such a great plugin!

       
odspi's avatar
odspi
29 posts
16 years ago
odspi's avatar odspi

Laisvunas, I appreciate your support here very much.

I tried the upgrade. It doesn’t seem to work. I cut&pasted;from this thread the new variable pairs and put them around the entries tags. The stuff inside isn’t rendered.

On a more general level.

I don’t know how difficult it is to implement,but the best option would be to render the stuff inside the plugin tags but outside the variable pairs as it is. This would be consistent with how normal ee tags work and will be the least surprising behavior for the coder and also be the most flexible.

But your solution should solve the biggest problem.

Thanks, hope the bug is shallow!

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

Hi odspi,

Can you post your code in which you added inside {entries_wrapper_top_start}{entries_wrapper_top_end} and {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} variable pairs some stuff which did not render?

It should not be the case that the code inside those variable pairs does not render at all; it may not be rendered something in some places where it should be, but not anything at all.

       
odspi's avatar
odspi
29 posts
16 years ago
odspi's avatar odspi
<div class="entry" id="catlist">        
{exp:child_categories parent="23" child_categories_sort_by="custom" 
child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" 
 entries_sort_direction="asc" entries_limit="3" site="1"}

  {parent_category_start}
  <h1><a href="http://{path={my_group}/C{parent_category_id}}">_         {parent_category_description}</a>
  </h1>
  {parent_category_end}

  {child_category_start}
   <div class="entry-title">    
   <h3><a href="http://{path={my_group}/C{child_category_id}}">_           {child_category_name}</a></h3>
   </div><!--  entry-title -->
   <div class="entry-footer">   Total entries: {entries_total}</div>

  {child_category_end}


{entries_wrapper_bottom_start}
  <ul>
{entries_wrapper_bottom_end}
  {entries_start}
              <li><a href="http://{path={my_group}/{url_title}}">{title}</a></li>
  {entries_end}
{entries_wrapper_bottom_start}
  </ul>
{entries_wrapper_bottom_end}


  {/exp:child_categories} 

</div><!-- entry -->
       
Laisvunas's avatar
Laisvunas
879 posts
16 years ago
Laisvunas's avatar Laisvunas

Hi odspi,

It’s easy to see where you have made simple oversight - you included variable pair {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} two times.

That is, instead of this

{entries_wrapper_bottom_start}
  <ul>
{entries_wrapper_bottom_end}

  {entries_start}
              <li><a href="http://{path={my_group}/{url_title}}">{title}</a></li>
  {entries_end}

{entries_wrapper_bottom_start}
  </ul>
{entries_wrapper_bottom_end}

there should be

{entries_wrapper_top_start}
  <ul>
{entries_wrapper_top_end}

  {entries_start}
              <li><a href="http://{path={my_group}/{url_title}}">{title}</a></li>
  {entries_end}

{entries_wrapper_bottom_start}
  </ul>
{entries_wrapper_bottom_end}

It is by design - wrapper code is being rendered only in case there are both {entries_wrapper_top_start}{entries_wrapper_top_end} and {entries_wrapper_bottom_start}{entries_wrapper_bottom_end} variable pairs.

       
odspi's avatar
odspi
29 posts
16 years ago
odspi's avatar odspi

Yes, I spotted it the moment I read my own post!!!

Shallow bug indeed! THANKS!

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

Hi,

I have released a version 1.4 of Child Categories plugin.

In this release parameter “invalid_input” was added. This parameter 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 the plugin finishes its work without any alert being shown. Set this parameter to “alert” for development, and to “silence” - for deployment.

Since the plugin does not do comprehensive validation of parameters’ values, you cannot be absolutely sure that in cases no alert was thrown the input was really valid.

       
1 2 3 4 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.