2

I've got a list of categories:

  • Category 1
    • Category 1.1
    • Category 1.2
    • Category 1.3
  • Category 2
    • Category 2.1
    • Category 2.2

An entry can be assigned to any child category, OR it can be assigned to just a parent category. For example:

  1. Entry 1: Category 1
  2. Entry 2: Category 1, Category 1.2

I want to display entries that are assigned to only the parent category, with no child categories. So I want Entry 1, but not Entry 2. The child categories will change, so I can't hard-code specific categories to exclude.

Ideas?


Update: Full Situation Description

I'm working on an online learning site. The class produces 4 types of study materials: study notes, videos, practice questions, and spreadsheets. Each of these types is a separate channel, since they require different custom fields.

The course is broken down into 3 tiers:

  • Part
    • Topic
      • Reading

A study item can cover just a reading, it can be a review for an entire topic, or it can be a review for an entire part.

I need to be able to display a list of study items that cover a particular Reading, a list of study items that review an entire Topic, or a list of study items that review an entire Part.

In addition, I need to be able to display a "new" icon in each Topic heading if a new study item in that topic or in its child readings has been added recently.

So this is where my problem comes in. I originally thought I could assign these items to categories, then output them based on category. But doing it that way I'm not able to display the items that are only assigned to a Topic, or only assigned to a Part.

What would be the best & most client-friendly way to organize these study items?

  • 1
    Are you sure this is the best approach? Almost every time I've seen people using nested parent/child categories (myself included!), it has been semantically inappropriate since the top level parents are not truly related to each other. Perhaps you'd be better off with a higher level of categorisation - specifically, using a custom field checkbox group (or even separate channels) for the parents. – James Smith May 2 '13 at 11:05
  • @James - I've updated my question with a more detailed description of what I'm trying to do. What would you recommend? – kmgdev May 2 '13 at 23:12
  • Ooh, that's a juicy complex problem... As you probably realised there are loads of different ways of approaching this. For better scalability I would be most inclined to create something like a 'course components' channel and use relationships to tie everything together: each course component entry would have a single select relationship field to select a 'parent component' (this creates the course hierarchy), then you'd have a Playa field to pull in the relevant study materials. – James Smith May 3 '13 at 0:32
  • I have yet to understand why so many people will do anything other than use EE categories. This is a great use case for categories! Why would you create the overhead of an ENTIRELY NEW CHANNEL? I mean, if you needed to actually worry about entry order or something, that would be one thing. But in the absence of that, this really is a perfectly cromulent use of categories. Especially since clients understand categories a lot better than they do Playa, usually. – adrienne May 3 '13 at 1:50
  • Two things: semantically, these are not 'categories' in the true sense - they're merely being used as a convenience because in EE cats support nested hierarchies. Second, by defining this as a new content type it gives you full flexibility and is future-friendly because it's a truer reflection of the nature of the content. You end up with a really clean separation: what happens in future if you want a particular topic to appear in multiple courses, or parts, or both? What happens when you have 500 readings and you need to limit some of them by logged-in member group? Etc ad nauseam... – James Smith May 3 '13 at 14:24
1

Primary Category from Solspace would do the trick. Allows you to set the main category and tie everything together nice and neatly.

It doesn't currently have any tags to output entries assigned to a primary category, so you'll have to write a custom plugin for the job.

| improve this answer | |
  • I agree that Primary Category could do this for you. You can set the Primary Category as the parent if it's not in a child category, and as the child if it is. Disagree with the GW Categories recommendation, though; it's great for small #s of categories but it will bog your site down like hell for large numbers of categories. – adrienne May 3 '13 at 1:53
  • Great comment about GW and thankfully I'm only using it in small doses, but PC is definitely much needed for what KG is trying to do! – Mark Busnelli Jr May 3 '13 at 14:27
  • I'm having trouble understanding exactly how Primary Category works - what are some example use cases? – kmgdev May 3 '13 at 14:59
  • In my case I'm passing a variable from the Primary Category down to one of the entries' to display a property logo on a Hospitality site like so: {exp:primary_category entry_id="{structure:page:entry_id}" parse="inward"} {exp:channel:entries channel="property" url_title="{primary_category_url_title}" disable="member_data|trackbacks" dynamic="off"} {property_logo}<img src="{exp:ce_img:single src='{image}' url_only='yes' width='288' height='174' crop='yes|center,center'}" alt="{alt}" />{/property_logo} {/exp:channel:entries} {/exp:primary_category} – Mark Busnelli Jr May 3 '13 at 15:32
  • Notice that you must change the parsing order so that the variable gets set correctly. This ties it all together. I hope that makes sense :) – Mark Busnelli Jr May 3 '13 at 15:34
2

If it were me I would create the course hierarchy/ies with Taxonomy (pulling in entries from a new 'course components' channel or similar). Then I'd create relationships in those entries with course materials via Playa. My reasoning is in the question's comments section, though obviously I am somewhat guessing since I don't know your exact situation.

http://devot-ee.com/add-ons/taxonomy

http://devot-ee.com/add-ons/playa

I like this most because it gives you all the power of channel entries and room to grow (maybe things like: commenting on course components; creating RSS feeds limited to single topics; limiting access to materials based on group permissions; selling course subscriptions via eCommerce, not to mention some of the Solspace stuff like tagging, ratings, favourites...)

Your client could create new dynamic courses from existing components without any repetition. Hell, your end users could even create their own bespoke courses by sticking together topics from diverse parts of a course (or multiple courses).

Let me see you do that with categories ;-)

| improve this answer | |
  • OK, so every Part, Topic, and Reading is part of the same channel (Course Components), and you use Taxonomy to assign the heirarchy. Then, inside each Part, Topic, and Reading entry is a Playa field, where you select which study items should be assigned to them? Aside from the extra advantages of the components being channel entries, isn't this basically just like using categories and turning off auto-assign parent? – kmgdev May 3 '13 at 18:04
  • I'm not wild about having to teach my client how to use Taxonomy, since they'd be adding new Topics & Readings themselves. I'd have to teach them which template group to use and all that jazz...not fun :/ – kmgdev May 3 '13 at 18:09
  • Yes it's the same end result, but the key difference is that entries are content while categories are meta-data. Consider this: how would you approach an online course that has no related study materials - basically an online book organised into an arbitrary hierarchy? With the category approach where would you store the book's content? Custom category fields? That's an even more finely-grained level of meta data. I would consider the parts, topics and readings to be 'content' the same as chapters of a book, even if the only content you currently have for them is a title and description. – James Smith May 3 '13 at 19:54
  • Kristen - Taxonomy isn't hard to use; they wouldn't have to worry about template groups or anything, i don't think. Just add the item, then go to taxonomy and add it to the hierarchy somewhere. I actually really like this suggestion. – adrienne May 4 '13 at 23:59
  • James, this is an excellent solution and thank you for sharing. I ended up accepting the Primary Category answer simply because it more specifically addresses the original question. But this solution is definitely valid as well. – kmgdev May 16 '13 at 16:07
1

I think the only way to do this would be to turn off Auto-Assign Category Parents in your Global Channel Preferences. That way Entry 2 is only assigned to Category 1.2. Like this instead:

  1. Entry 1: Category 1
  2. Entry 2: Category 1.2

That may be a deal breaker for you, but it's hard to say since I'm not sure how you intend to use these categories on your site.

Then it depends on what you want your output to look like. If you want to get entries listed by parent category, you could use {exp:channel:category_archive} tag if you only need entry titles.

{exp:channel:category_archive channel="topic_pages" style="linear"}
  {categories}
    {if parent_id == 0}
      <h3>{category_name}</h3>
      {entry_titles}
        <p>{title}</p>
      {/entry_titles}
    {/if}
  {/categories}
{/exp:channel:category_archive}

Or you can try nesting the {exp:channel:entries} tag inside {exp:channel:categories} tag if you need more information like custom fields.

{exp:channel:categories category_group="1" style="linear" parent_only="yes"}
  <h3>{category_name}</h3>
  {exp:channel:entries category="{category_id}"}
    <p>{title}</p>
  {/exp:channel:entries}
{/exp:channel:categories}

This will give you...

Category 1
Entry 1

Category 1
Entry 4
Entry 6

etc.

I haven't tried this yet, but it may be possible to get the same thing more simply with the NSM Categories add-on.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.