3 of 19
3
Plugin: Child Categories
Posted: 01 September 2008 11:10 AM   [ Ignore ]   [ # 37 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

Hi,

Just released version 1.4.1 of Child Categories plugin.

In this release a bug was fixed: PHP error message being shown in cases when “sibling” parameter’s value contain a string which is not id number of any category.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 01 September 2008 01:13 PM   [ Ignore ]   [ # 38 ]  
Summer Student
Total Posts:  9
Joined  08-17-2006

Hi, thanks for such a fast response! I certainly was pleased to start work this morning and have such a good start on my day’s work! Thank you!

I have taken your advice and gone with the first approach you suggested to construct my links, and that solved my issue with constructing links.

I only have one issue left to resolve, which I am hopeful you can help me with: for the parent categories that don’t have anything in the {description} field, I want to show them without a link, and if they have something in the {description} field, I want to show them with a link.

Here is my code, which shows what I am trying to accomplish. It just doesn’t seem that the {if} tag works inside the {exp:child_categories} tag. Am I missing something?

<h2>child_categories plugin</h2>

{exp:child_categories weblog="hr_aps" parent="50|51|52|53|54|55" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no" entries_sort_by="date" entries_sort_direction="asc" entries_limit="6"}

  {if description
!= ""}
    {parent_category_start}
      
<h3><a href="{path=hr/areas_of_practice_detail}{parent_category_id}/">{parent_category_name}</a></h3>
    
{parent_category_end}

  {if
:else}
    {parent_category_start}
      
<h3>{parent_category_name}</h3>
    
{parent_category_end}
  {
/if}

  {child_category_start}
  {child_category_end}

  {entries_wrapper_top_start}
    
<ul>
  
{entries_wrapper_top_end}

  {entries_start}
    
<li><a href="{path=hr/areas_of_practice_services_2}{url_title}/">{title}</a></li>
  
{entries_end}

  {entries_wrapper_bottom_start}
    
</ul>
  
{entries_wrapper_bottom_end}

{
/exp:child_categories}

Here is a link to my latest creation, based off of your previous advice. http://hruhpa.com.s18903.gridserver.com/index.php/hr/areas_of_practice_listing

And thank you again for making yourself and your talents so freely accessible. Once I get this resolved, I’d love to make a Paypal donation to you or your charity of choice. Just PM me the details.

Profile
 
 
Posted: 02 September 2008 03:16 AM   [ Ignore ]   [ # 39 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

Hi jdgraffam,

It just doesn’t seem that the {if} tag works inside the {exp:child_categories} tag.

Correct. Conditionals currently are not supported by Child Categories plugin.

Still, it seems that what you need can be achieved using Child Categories plugin together with {exp:weblog:categories} tag.

There are several things to be noted:

1) No code should be outside variable pairs
{parent_category_start}{parent_category_end}
{child_category_start}{child_category_end}
{entries_start}{entries_end}
{entries_wrapper_top_start}{entries_wrapper_top_end}
{entries_wrapper_bottom_start}{entries_wrapper_bottom_end}

2) {exp:child_categories} tag must have parse=“inward” parameter.

3) Both {exp:child_categories} tag and {exp:weblog:categories} tag must have “weblog” parameter which specifies only one weblog.

The code should be approximately as follows:

{exp:child_categories weblog="hr_aps" parent="50|51|52|53|54|55" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="no" entries_sort_by="date" entries_sort_direction="asc" entries_limit="6" parse="inward"}

{parent_category_start}
{exp
:weblog:categories style="linear" weblog="hr_aps"}
{if category_id
=="{parent_category_id}" AND category_description!=""}
<h3><a href="{path=hr/areas_of_practice_detail}{category_id}/">{category_name}</a></h3>
{/if}
{if category_id
=="{parent_category_id}" AND category_description==""}
<h3>{category_name}</h3>
{/if}
{
/exp:weblog:categories}
{parent_category_end}


  {child_category_start}
  {child_category_end}



  {entries_wrapper_top_start}
    
<ul>
  
{entries_wrapper_top_end}


  {entries_start}
    
<li><a href="{path=hr/areas_of_practice_services_2}{url_title}/">{title}</a></li>
  
{entries_end}


  {entries_wrapper_bottom_start}
    
</ul>
  
{entries_wrapper_bottom_end}


{
/exp:child_categories}
 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 08 September 2008 03:28 PM   [ Ignore ]   [ # 40 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  530
Joined  04-23-2008

This sounds really cool! Does someone have a live example of its usage I can take a look at for some inspiration? smile

 Signature 

Danny Tam » Twitter | LinkedIn | Facebook | Flickr

Profile
 
 
Posted: 11 September 2008 11:11 PM   [ Ignore ]   [ # 41 ]  
Grad Student
Rank
Total Posts:  70
Joined  02-02-2006

Nice plugin. And for a noob like me, I actually sort of got it working. Here is my problem and hopefully someone will be able to help. 

I am using this for a three tier navigation. I have the tiers specified as categories. Example:

About Us (Tier 1/Template)
- HQ Location (Tier 2/Weblog)
- Contact Information (Tier 2/Weblog)
- - Email (Tier 3/Weblog)
- - Phone (Tier 3/Weblog)
- - Mailing (Tier 3/Weblog)
- Business Principles (Tier 2/Weblog)
Services (Tier 1/Template)

The page will have the tier 1 items across the top (never changes). Tier 2 and Tier 3 will be along the right side.  Tier 2 on the top and Tier 3 on the bottom (using div within the templates)

Using the code below, when a person navigates to a Tier 2 page, the Tier 3 (child categories) appear in the bottom div on the right. The problem however, is once they have navigated to a Tier 3 page, the bottom navigation is now blank. From what I can understand and it makes sense, once they are on a tier 3 page; there are no child categories and therefor it will not show up. Is there a way using IF statements to have it where when they are on a tier 3 page it will continue to show the categories in the bottom div as if they are really on a tier 2 page? Remember I am using one template for both the Tier 2 and Tier 3 pages.

{exp:category_id category_group=“8” category_url_title=”{segment_2}” parse=“inward”}
  {exp:child_categories parent=”{category_id}” site=“2” show_empty=“yes” entries_limit=“5” parse=“inward”}
  {child_category_start}
  {child_category_name}
  {child_category_end}

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

I saw something about using a sibling instead which seems to work when they on a a tier 3 but when on a tier 2 the page displays errors.


Notice: Undefined variable: parent_cat_description in /home/honourhe/public_html/hcsystem/plugins/pi.child_categories.php on line 474

Notice: Undefined variable: parent_cat_image in %SITEPATH%/plugins/pi.child_categories.php on line 475

Any ideas?

Profile
 
 
Posted: 12 September 2008 11:51 AM   [ Ignore ]   [ # 42 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

Is there a way using IF statements to have it where when they are on a tier 3 page it will continue to show the categories in the bottom div as if they are really on a tier 2 page? Remember I am using one template for both the Tier 2 and Tier 3 pages.

{exp:category_id category_group=“8” category_url_title=”{segment_2}” parse=“inward”}
{exp:child_categories parent=”{category_id}” site=“2” show_empty=“yes” entries_limit=“5” parse=“inward”}
{child_category_start}
{child_category_name}
{child_category_end}

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

As I can see from your code, in Tier 2 pages you get category_url_title from segment_2 and convert it to category_id.

In order to show the same categories in Tier 3 pages you should somehow pass value of segment_2 from Tier 2 page to Tier 3 page. To do this most convenient way is to use some other URL segment variable (EXpressionEngine supports 9 URL segment variables).

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 12 September 2008 12:50 PM   [ Ignore ]   [ # 43 ]  
Grad Student
Rank
Total Posts:  70
Joined  02-02-2006

Thanks for your reply Laisvunas.

Unfortunately, since I am using one template for both the tier 2 and tier 3 items, there is no segment_3 define.
So, no matter if they are on a tier 2 or a tier 3 page, the url is still only index.php/About_Us/{page_name}.

Unless there is a way to make a tier 3 page become a segment_3 in the URL without having to make additional templates, is there?

So using the example:

About Us (Tier 1/Template)
- HQ Location (Tier 2/Weblog)
- Contact Information (Tier 2/Weblog)
- - Email (Tier 3/Weblog)
- - Phone (Tier 3/Weblog)
- - Mailing (Tier 3/Weblog)
- Business Principles (Tier 2/Weblog)

When on the Contact Information page the url is /index.php/Services/contact_info
When on the Email page the page url is /index.php/Services/email

Is it possible to define the tier3 pages as segment_3 (/index.php/Services/contact_info/email) without having another template? If not, how else would I handle this problem?

Thanks

Profile
 
 
Posted: 13 September 2008 03:48 AM   [ Ignore ]   [ # 44 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

Unfortunately, since I am using one template for both the tier 2 and tier 3 items, there is no segment_3 define.
So, no matter if they are on a tier 2 or a tier 3 page, the url is still only index.php/About_Us/{page_name}.

You can easily form URLs which are placed in Tier 2 pages and lead to Tier 3 pages this way:

ndex.php/About_Us/page_name/{segment_2}/

Then add simple conditional inside category_url_title parameter of exp:category_id tag:

{exp:category_id category_group="8" category_url_title="{if segment_2=="some_tier_2_segment" OR segment_2=="some_other_tier_2_segment"}{segment_2}{/if}{if segment_2=="some_tier_3_segment" OR segment_2=="some_other_tier_3_segment"}{segment_3}{/if}" parse="inward"}
{exp
:child_categories parent="{category_id}" site="2" show_empty="yes" entries_limit="5" parse="inward"}
{child_category_start}
<p><a href="{homepage}/Services/{child_category_url_title}/">{child_category_name}</a>
{child_category_end}

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

This way you will pass segment_2 of Tier 2 page to Tier 3 page as its segment_3; and using conditional you will pass it as value of category_url_title parameter of exp:category_id tag.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 19 September 2008 03:23 PM   [ Ignore ]   [ # 45 ]  
Grad Student
Rank
Total Posts:  70
Joined  02-02-2006

Sorry for the delayed response. Located in Houston, so we havent had any power.

I am obviously missing something. When I use more than one OR statement nothing shows up; no matter the condition.  Using the code provided, I changed the “some_tier2_segment” to an actual segment name. If I use only one condition, that page will work then the others will fail with the following errors:

Notice: Undefined variable: parent_cat_description in /home/[sitepath]/plugins/pi.child_categories.php on line 474 and line 475. followed by what appears to be a full list of all of the sites categories.

Also, one other thing that might be a problem once this works is that I am having to hard code the segment names in the condition. This will prevent the site from being dynamic as I would hope it to be.

Curious, is the Categories in EE fairly new? Seems that what I am trying to do should be pretty straight forward.

Thanks again,

Profile
 
 
Posted: 20 September 2008 02:55 AM   [ Ignore ]   [ # 46 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

If segment conditional does not work inside parameter, then try to wrap with that conditional entire tag.

if you do not want to hardcode possible segment values, then at first check for existence of certain segment.

The code would be approximately as follows:

{if segment_3!=""}

{exp
:category_id category_group="8" category_url_title="{segment_3}" parse="inward"}

{exp
:child_categories parent="{category_id}" site="2" show_empty="yes" entries_limit="5" parse="inward"}

{child_category_start}
<p><a href="{homepage}/Services/{child_category_url_title}/">{child_category_name}</a>
{child_category_end}

{
/exp:child_categories}

{
/exp:category_id}

{
/if}

{if segment_3
==""}

{exp
:category_id category_group="8" category_url_title="{segment_2}" parse="inward"}

{exp
:child_categories parent="{category_id}" site="2" show_empty="yes" entries_limit="5" parse="inward"}

{child_category_start}
<p><a href="{homepage}/Services/{child_category_url_title}/">{child_category_name}</a>
{child_category_end}

{
/exp:child_categories}

{
/exp:category_id}

{
/if}
 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 23 September 2008 01:19 PM   [ Ignore ]   [ # 47 ]  
Grad Student
Rank
Total Posts:  70
Joined  02-02-2006

Thanks! That worked for the tier 3 items. Now trying to get the tier 2 items to display. I would have thought using Segment_1 would do the trick, but that seems to cause errors.  Hmm…

Just to backtrack a bit. The navigation is 3 tier. Tier 1 is along the top, Tier 2 is in a <div> on the upper right and Tier 3 is also in a <div> on the lower right side.  Tier 1 is static. Currently Tier 2 is also static with the dynamic Tier 3 using the code above. Again thanks for that!  Now if I can get Tier 2 to be dynamic, I will be set.

About Us (Tier 1/Template - static/top nav)
- HQ Location (Tier 2/Weblog - dynamic/right top nav)
- Contact Information (Tier 2/Weblog - dynamic/right top nav)
- - Email (Tier 3/Weblog - dynamic/right bottom nav)
- - Phone (Tier 3/Weblog - dynamic/right bottom nav)
- - Mailing (Tier 3/Weblog - dynamic/right bottom nav)
- Business Principles (Tier 2/Weblog - dynamic/right top nav)
- Some other category (Tier 2/Weblog - dynamic/right top nav)
Services (Tier 1/Template - static/top nav)

Using this code, I got it to display the parent category, but it only shows the first (HQ Location) in the list. There are three.

{exp:category_id category_group=“8” category_url_title=”{segment_2}” parse=“inward”}

{exp:child_categories parent=”{category_id}” site=“2” show_empty=“no” entries_limit=“5” parse=“inward”}

{parent_category_start}
{parent_category_name}
{parent_category_end}

{/exp:child_categories}

{/exp:category_id}

Thanks!

Profile
 
 
Posted: 24 September 2008 12:02 PM   [ Ignore ]   [ # 48 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

If I understood you correctly, you have 3 levels of categories

Category level 1
Category level 2, that is child category of the category level 1
Category level 2, that is child category of the category level 2

and you would like by setting category id of category level 1 as the value of “parent” parameter of exp:child_categories tag to display categories of all three levels.

Unfortunately this is impossible because Child categories plugin can display only two levels of categories.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 29 September 2008 08:19 AM   [ Ignore ]   [ # 49 ]  
Grad Student
Rank
Total Posts:  73
Joined  02-10-2004
{exp:child_categories parent="{category_id}" child_categories_sort_by="custom" child_categories_sort_direction="asc" show_empty="yes" entries_sort_by="date" entries_sort_direction="asc" entries_limit="5"}

  {parent_category_start}
  
<p class="category_name"><a href="{homepage}/{thisblog}/category/{parent_category_url_title}/">{parent_category_name} - Index</a></p>
  
{parent_category_end}

  {child_category_start}
  
&nbsp;-&nbsp;<b><a href="{homepage}/{thisblog}/category/{child_category_url_title}/">{child_category_name}</a></b>&nbsp;({entries_total})<br />
  
{child_category_end}

  {
/exp:child_categories}

Thank you SO much for this plugin. I am HOPING there is a way to display not just the current child categories but the categories one level below the current. For example:

http://www.thrivingnow.com/for/Health/category/eft-resources-more

- Learning EFT (3)
- EFT Coaching (2)
- EFT Experts (5)
- - Carol Look (11)
- - Gary Craig (2)
- EFT Talk (3)
- EFT Audio Tips (10)


Any way to get that level of recursion?

Rick

Profile
 
 
Posted: 29 September 2008 09:31 AM   [ Ignore ]   [ # 50 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

Hi Rick,

I am HOPING there is a way to display not just the current child categories but the categories one level below the current.

Of course, there is. You can use exp:weblog:categories tag or exp:weblog:category_archive tag.

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 30 September 2008 06:26 AM   [ Ignore ]   [ # 51 ]  
Lab Technician
Avatar
RankRankRankRank
Total Posts:  1130
Joined  02-15-2008

Superb plugin, did exactly what I needed. Great work Laisvunas.

 Signature 

Andy Harris | Pepper Digital | Malvern, UK | Twitter | New to ExpressionEngine? Start here!

Profile
 
 
Posted: 30 September 2008 09:34 AM   [ Ignore ]   [ # 52 ]  
Grad Student
Rank
Total Posts:  73
Joined  02-10-2004
Laisvunas - 29 September 2008 09:31 AM

Hi Rick,

Of course, there is. You can use exp:weblog:categories tag or exp:weblog:category_archive tag.

I guess I am being dense on how to use those when what I want is the CHILD category structure ONLY, based on the current category. Am I using one of these in conjunction with your plugin? If so, a tip where to plug it in would help.

Thanks!
Rick

Profile
 
 
Posted: 30 September 2008 09:57 AM   [ Ignore ]   [ # 53 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  884
Joined  02-02-2007

Hi Rick,

I’m not sure that I have understood you correctly.

Correct me if I a wrong.

1) You have three levels of categories.
2) Current category is the category of level 1 (that is, of highest level).
3) You need to display current category’s child categories (belonging to level 2) and their child categories (belonging to level 3).

 Signature 

Full list of add-ons here

Child Categories
Browser Sniff
Category Id
Entries Number

Profile
 
 
Posted: 30 September 2008 10:06 AM   [ Ignore ]   [ # 54 ]  
Grad Student
Rank
Total Posts:  73
Joined  02-10-2004

1) You have three levels of categories.
—Right now, yes, but I would like to go to 4 in some cases.

2) Current category is the category of level 1 (that is, of highest level).
—Not necessarily. The template doesn’t know for sure that it is at the highest level. In the example I gave, EFT Resource & More is a top level category. Same code needs to work, though, if I am showing a level 2 category index.

3) You need to display current category’s child categories (belonging to level 2) and their child categories (belonging to level 3).
—Yes, if I am at level 1. If at level 2, I’d like to show current category’s children and their child categories as well.

Current Category Name - Index

- Child 1 (10)
—Child A (3)
- Child 2 (7)
—Child F (1)
—Child G (6)

Clearer? And thanks so much for staying with me on this. I’d really like to get my site structure working smoothly, and your plugin has already helped considerably. I used to have the whole hierarchy displayed in the sidebar of every page!

Rick

Profile
 
 
   
3 of 19
3
 
Post Marker Legend
New Topic New posts Hot Topic Hot Topic with new posts New Poll New Poll Moved Topic Moved Topic Sticky Topic Sticky topic
Old Topic No new posts Hot Old Topic Hot Topic with no new posts Old Poll Old Poll Closed Topic Closed Topic Announcement Announcements
Theme
Change Theme
Visitor Statistics
The most visitors ever was 1743, on December 02, 2009 03:47 PM
Total Registered Members: 120512 Total Logged-in Users: 73
Total Topics: 126580 Total Anonymous Users: 36
Total Replies: 665474 Total Guests: 326
Total Posts: 792054    
Members ( View Memberlist )
Newest Members:  12sarah123CasERispukgendaleOptimizaiofficeiEclipsekinkadebbbBenAbramsasantisteban