Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2011-01-12 06:56:15

jammer
Member
Registered: 2009-01-13
Posts: 36

Subcategories

Hello,

I’m trying to get a list of my ‘subcategories’ on a landing page when i click on the ‘parent category’ in the sidebar. Is there a way to do this using only Textpattern code or do I have to use a plugin to (which plugin would work here) achieve this….?

Thanks in advance

RJ

Offline

#2 2011-01-12 07:31:03

colak
Admin
From: Cyprus
Registered: 2004-11-20
Posts: 9,254
Website GitHub Mastodon Twitter

Re: Subcategories

I think that this might work

<txp:category_list parent='<txp:category />' exclude='<txp:category />' break="" wraptag="ul">
<li><txp:category title="1" link="1" />
</txp:category_list>

Yiannis
——————————
NeMe | hblack.art | EMAP | A Sea change | Toolkit of Care
I do my best editing after I click on the submit button.

Offline

#3 2011-01-12 14:47:34

jammer
Member
Registered: 2009-01-13
Posts: 36

Re: Subcategories

Colak,

Your code lists all categories and subcategories in my sidebar. What I need to do is list ONLY the parent categories in the sidebar and when a parent category is clicked, ONLY the subcategories for that particular category is listed on the landing page…. sans articles. THEN, when a subcategory is clicked, the articles for THAT subcategory is then listed on the article page.

I use this code that does list the parent categories in the sidebar, but I cannot get it to list ONLY the subcategory names in the landing page.

RJ


<txp:if_section name="holiday">
    <txp:category_list parent="parent-category" exclude="parent-category" categories="england,france,germany,italy" wraptag="ul" break="">
        <txp:if_first_category>
            <li<txp:if_category name='<txp:category />'> class="active"
<txp:else />
<txp:if_category>
<txp:else />
<txp:if_article_list> class="active"</txp:if_article_list>
</txp:if_category>
</txp:if_category>>
<txp:category title="1" link="1" this_section="1" /></li>
        <txp:else />
            <li<txp:if_category name='<txp:category />'> class="active"</txp:if_category>><txp:category title="1" link="1" this_section="1" /></li>
        </txp:if_first_category>
    </txp:category_list>
</txp:if_section>

Offline

#4 2011-01-12 16:23:54

jammer
Member
Registered: 2009-01-13
Posts: 36

Re: Subcategories

I should add that each category & subcategory will have a description which is displayed along with the category name on the landing page.

Again, thanks in advance….

RJ

Offline

#5 2011-01-12 20:31:57

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Subcategories

I think I understand what you want to do, but I find this: parent="parent-category" exclude="parent-category" categories="england,france,germany,italy" a bit confusing. You either use the parent and exclude attributes, or the categories attribute, not all three of them in one tag. How many category levels are there? Are ‘england’, ‘france’ etc. your parent categories that each have subcategories? Do ‘england’ etc. have a parent category of their own?

Is this what you’re after?

on section page ‘holidays’:

  • England
  • France
  • Germany
  • Italy

on each of the above category pages:

  • subcat1
  • subcat2
  • etc

on each of these subcat pages:

  • article1
  • article2

Offline

#6 2011-01-12 21:42:31

jammer
Member
Registered: 2009-01-13
Posts: 36

Re: Subcategories

Els,

Thats exactly what I’m trying to achieve…… thanks,

RJ

Offline

#7 2011-01-12 22:03:32

jammer
Member
Registered: 2009-01-13
Posts: 36

Re: Subcategories

Els,

Holiday is the “Section”

There are four categories…. England, France, Germany, Italy.

Then there are a number of sub-categories to which articles will be assigned (i.e)

For ‘Category’ England —‘subCategories’ — Dining, Hotels, Transportation
For ‘Category’ France — ‘subCategories’ — Cities, Wineries

etc….

Note: The subcategories for each category wont necessarily be the same.

RJ

Offline

#8 2011-01-12 23:45:55

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Subcategories

OK, try this. I only used the single tags to keep the example as short as possible, so you’ll need to change the single tags back to container tags and add the active class and so. I haven’t tested it, hope it works.

<txp:if_section name="holiday">
   <txp:if_article_list>
      <txp:if_category>
         <txp:if_category name="england,france,germany,italy">
            <!-- parent category page, show list of subcategories -->
            <txp:category_list parent='<txp:category />' exclude='<txp:category />' />
         <txp:else />
            <!-- subcategory page, show article list -->
            <txp:article_custom section="holiday" category='<txp:category />' />
         </txp:if_category>
      <txp:else />
         <!-- section page, show list of parent categories -->
         <txp:category_list categories="england,france,germany,italy" />
      </txp:if_category>
   <txp:else />
      <!-- individual article page, show something else? -->
   </txp:if_article_list>
</txp:if_section>

Offline

#9 2011-01-13 00:12:51

jammer
Member
Registered: 2009-01-13
Posts: 36

Re: Subcategories

Thanks Els,

Will test it & get back to you…

Offline

#10 2011-01-14 17:33:29

jammer
Member
Registered: 2009-01-13
Posts: 36

Re: Subcategories

Els,

I tested your code and I keep getting a blank page. I used the following code & I was able to get each section to list their assigned categories correctly in the sidebar, but

1. It lists the child categories as well & I need ONLY the parent category in the sidebar & when clicked, lists the respective child categories on the landing page. ( don’t know if thats possible)

2. All the articles appear under one section only even though some articles are not assigned to that section.

<txp:if_section name='<txp:section />'>
    <txp:if_article_list>
        <txp:if_category name='<txp:category />'>
            <!-- one of the category pages -->
            <txp:article form="default" listform="article_listing" limit="99" />
        <txp:else />
            <!-- section landing page -->
            <txp:article_custom section='<txp:section />' category='<txp:category />' form="default" />
        </txp:if_category>
    </txp:if_article_list>
</txp:if_section>

Offline

#11 2011-01-14 17:36:57

jammer
Member
Registered: 2009-01-13
Posts: 36

Re: Subcategories

Sorry, The code in the previous post is the code for the section page. This is the code I used to load the categories in the sidebar is below….

<txp:category_list label="Categories" parent='<txp:section />' exclude='<txp:section />' this_section="1" />

Thanks

RJ

Offline

#12 2011-01-14 19:39:44

els
Moderator
From: The Netherlands
Registered: 2004-06-06
Posts: 7,458

Re: Subcategories

1. It lists the child categories as well & I need ONLY the parent category in the sidebar & when clicked, lists the respective child categories on the landing page. ( don’t know if thats possible)

Add childred="0" to the category_list tag. Forgot that, sorry.

2. All the articles appear under one section only even though some articles are not assigned to that section.

Do you mean the article list in the sidebar? This: <txp:article_custom section="holiday" category='<txp:category />' /> can only display articles from section ‘holiday’ (the same goes for <txp:article_custom section='<txp:section />' category='<txp:category />' /> when in section ‘holiday’).
Can you post the entire block of code you are using now?

Edit: or maybe there are articles in section ‘holiday’ with other categories (besides england, france etc. and their subcategories), that shouldn’t be displayed? I didn’t cover that in my code example.

Last edited by els (2011-01-14 19:43:09)

Offline

Board footer

Powered by FluxBB