MashPayne.de

how to list sibling-categories?

Vote 0 Votes

Hi at all,

I'm new to movable type and I'm still trying to understand the way it works.

This is my problem:

I have two main categories. "EN" and "DE" which stands for english and german content. Both have the same subcategory-structure.
Within these main categories are 2 layers of subcategories.
I'll try to illustrate:

EN
-->SubCatA
-->SubSubCatA1
-->SubSubCatA2
-->SubSubCatA3
-->SubCatB
-->SubSubCatB1
-->SUbSubCatB2
-->SubSubCatB3
-->SubCatC
...and so on... (same for the DE-Category)

Now if a user enters a SubCat, I want to show him a submenu of all children belonging to this SubCat (SubSubCat A1,A2 and A3).
This, I think, I solved:


<ul>
<MTSubCategories>
<li><a href="<$MTArchiveLink$>"><$MTArchiveTitle$></a></li>
</MTSubCategories>
</ul>

So far so good. But if the user enters one of thes SubSubCats I still want to show him the exact same submenu. So I have to generate a submenu, that contains all sibling-categories of the SubSubCat the user is into.

So how do I have to do this?
I tried to loop through all categories and display just the subSubCats of the Subcat I'm in, but I didn't find something like

<mt:if tag="categoryLabel" like="the-current-Subcat-I'm-in">
//show all SubSubCats
</mt:if>

I have to do this dynamically, so I somehow need a variable that contains the current Subcategory the user is in.

Could anybody help me please?

Thank you in advance!

greets Michael.

Reported on Movable Type 5

9 Replies

| Add a Reply
  • Hi Michael,

    For the subsubcategory you would have to set a variable with its parent category, which in this case would be a subcategory.

    Then, you would list all the entries inside that subcategory, eventually marking the current one in context, either assigning it a class or making it bold.

    Kind Regards,
    Mihai Bocsaru

    ----------------------------------
    Daily Movable Type Consultant

    Web Development
    Movable Type Consulting
    Six Apart Partner

    http://www.pro-it-service.com/
    ----------------------------------

    Movable Type Demo
    http://www.movabletypedemo.org/
    ----------------------------------

    Open Melody Demo
    http://www.openmelodydemo.org/

  • MashPayne.de

    Hi Mihai,

    thank you for your fast reply!

    Could you please give me a example on how to get the name of the parent category? I'm still a little bit lost in the MT-Tag language.
    All I find is how to loop through all categories and list them up. I don't know how to say "get Parent Category of the current Category"

    Assuming that i have that parent category variable, I would do the following:

    <ul>
     <mt:Categories category="parent category">
      <li>
       <a href="<$MTArchiveLink$>"><$MTArchiveTitle$></a>
      </li>
     </mt:Categories>
    </ul>
    

    is that the right way to do? (regardless of marking the current subcategory)

    Thank you very much!

    greets,
    Michael

  • Hi Michael,

    You are welcome!

    Here are some hints from the documentation:
    http://www.movabletype.org/documentation/appendices/tags/setvarblock.html
    http://www.movabletype.org/documentation/appendices/tags/hasparentcategory.html
    http://www.movabletype.org/documentation/appendices/tags/parentcategory.html

    You could get the parent category of the current category in context using:
    <mt:ParentCategory><mt:CategoryLabel></mt:ParentCategory>

    Setting it as a variable could be done using:
    <mt:HasParentCategory><mt:SetVarBlock name="parent_category"><mt:ParentCategory><mt:CategoryLabel></mt:ParentCategory></mt:SetVarBlock></mt:HasParentCategory>
    (the above could work also without the mt:HasParentCategory)

    Invoking the parent category works like this:
    <mt:Categories category="$parent_category">

    Of course, you would have to play a bit with this coding until you get what you wanted.

    Kind Regards,
    Mihai Bocsaru

  • MashPayne.de

    Thank you very much, again!

    When I try your code I get 2 error messages.
    1. MTHasParentCategory has to be within a category-context

    if I wrap the <mt:HasParentCategory> with <mt:Categories>


    <mt:Categories>
    <mt:HasParentCategory>...</mt:HasParentCategory>
    </mt:Categories>


    the lines:


    <ul>
    <mt:Categories category="$parent_category">
    <li><a href="<$MTArchiveLink$>"><$MTArchiveTitle$></a></li>
    </mt:Categories>
    </ul>

    produce the other error:
    2. Can't call method "entry_based" on an undefined value

    what does that mean?

    Maybe it's important to know, that this submenu is placed within a widget, that is included in the footer-widget, which is placed within the Entry-list archive template (don't know the exact english translation for this)

    I hope I don't bother you to much! Thank you again for your help!


    greets,
    Michael

  • Of course that you have to include that coding inside a category context...

    Is that widget called only fron the "Entry Listing" archive template? Also, since you are getting the 1st error, I guess that you are not publishing only categories, but also monthly archives, if not also author archives and also category monthly archives...

    A link to your site would also help!

  • MashPayne.de

    I'm still having the problem, with this "category context"

    I moved the listing inside the "beta-column" (div id="beta-inner"). By the way, I'm using the "Professionelles Blog 1.0", if it's important.

    here is my code:

    <mt:HasParentCategory>
     <mt:SetVarBlock name="parent_category">
      <mt:ParentCategory>
       <mt:CategoryLabel>
      </mt:ParentCategory>
     </mt:SetVarBlock>
    </mt:HasParentCategory>
    
    

    <ul>
    <mt:SubCategories category="$parent_category">
    <li>
    <a href="<$MTArchiveLink$>"><$MTCategoryLabel$></a>
    </li>
    </mt:SubCategories>
    </ul>

    i can wrap around <mt:categories>...</mt:categories> around the first block, but then MT goes trough all categories. I want to do this:

    <mt:Go-ONLY-into-the-current-category>
     <mt:HasParentCategory>
      <mt:SetVarBlock name="parent_category">
       <mt:ParentCategory>
        <mt:CategoryLabel>
       </mt:ParentCategory>
      </mt:SetVarBlock>
     </mt:HasParentCategory>
    </mt:Go-ONLY-into-the-current-category>
    

    Which "category context" can I put around the <mt:HasParentCategory> that MT just graps the current SubSubCategory the user is in an checks if it has a parent category? Isn't there any variable, that contains the current category?

    here is the link Nevermind the design, it's not mine ;-)
    Thanks again!

  • MashPayne.de

    Looks like my last post didn't show up in the thread... don't know why...

    I'll repeat the post.Here we go:

    I moved the code from the widget directly into the Entry listing archive template but I still have the problem with the "category context".

    here ist my code:

    <mt:HasParentCategory>
     <mt:SetVarBlock name="parent_category">
      <mt:ParentCategory>
       <mt:CategoryLabel>
      </mt:ParentCategory>
     </mt:SetVarBlock>
    </mt:HasParentCategory>
    
    

    <mt:SubCategories category="&parent_category">
    <li><a href="<$MTArchiveLink$>"><$MTCategoryLabel$></a></li>
    </mt:SubCategories>

    what tag can I wrap around the MTHasParentCategories, that its still within a category context and only checks the current category the user is in? Isn't there any variable, that stores the current category the user is in?

    for Example, If i hard code


    <mt:categories category="activities">

    everything works fine, but I need this dynamically.

    Thank you again! I'm somehow getting desperate... :-(

  • MashPayne.de

    Sorry for the double post.

    here is the link
    nevermind the design...it's not from me ;-)

    greets,
    Michael

  • MashPayne.de

    here is the link, sorry for double post

    http://www2.fremde-werden-freunde.de/

    greets,
    Michael

Add a Reply

If you need to share template code, replace all the "<" signs with "&lt;" or use this utility.

Forum Groups

1774 6167

Last Topic: Template modules by Zielun on Feb 16, 2012

86 302

Last Topic: website entries by masoud on Oct 26, 2011

1434 5088

Last Topic: Maintenance announcement by Nick on Feb 17, 2012

695 2912

Last Topic: Insert Image / File Fails by Russ Miller on Feb 10, 2012

84 291

Last Topic: How to have some other characters in entry basename automatically written by Afshin Haghighatnia on Dec 22, 2011

174 740

Last Topic: Captcha images rendering slowly by ScottM on Feb 12, 2012

190 568

Last Topic: Analytics Reporting by michael webster on Feb 5, 2012

48 210

Last Topic: An idea and also a request by Afshin Haghighatnia on Jun 29, 2011

64 246

Last Topic: jQuery in MT 5.1 still at 1.4 - why? by perlmonkey on May 25, 2011

code.sixapart.com

137 478

Last Topic: Getting a thumbnail with xpath by Peter on Mar 13, 2011

222 720

Last Topic: Custom Field for Asset Not Appearing by android on Feb 9, 2012