Jump to content

Article with multiple categories


nikola
 Share

Recommended Posts

I'm trying to fetch articles based on category selection.

I have the following setup:

  • Category
    • Category 1
      • Subcategory 1
        • Article 1
        • Article 2
        • Article 3

        [*]Subcategory 2

        • Article 1
        • Article 2
        • Article 3

        [*]Subcategory 3

        • Article 1
        • Article 2
        • Article 3

        [*]Subcategory 4

        • Article 1
        • Article 2
        • Article 3

        [*]Subcategory 5

        • Article 1
        • Article 2
        • Article 3

      [*]Category 2

      • Subcategory 1
        • Article 1
        • Article 2
        • Article 3

        [*]Subcategory 2

        • Article 1
        • Article 2
        • Article 3

        [*]Subcategory 3

        • Article 1
        • Article 2
        • Article 3

        [*]Subcategory 4

        • Article 1
        • Article 2
        • Article 3

        [*]Subcategory 5

        • Article 1
        • Article 2
        • Article 3

I've made "categories" field with a type of: "Page" where I select Category as parent for categories.

All articles have the same template - "article".

I want to add categories to Page reference field assigned to "article" template so I can pull them on the front end.

Let's say I want to add articles on front end from Category 1 - Subcategory 1, Category 2 - Subcategory 1, Category 2 - Subcategory 3 that use the same template - article and have same categories set in the categories Page reference field.

Link to comment
Share on other sites

I'm not sure that I understand the question?

But you did say that you want a categories Page reference on the article template. That makes me think that you probably don't want the articles structured under the subcategories and instead maybe they should all be under /articles/ ? Then you'd select categories/subcategories from the Page reference field using something like PageListSelectMultiple or PageAutocomplete. That would at least solve the issue of articles that need multiple categories/subcategories (though not sure if this is something you needed or not?)

Link to comment
Share on other sites

That would solve my problem and would be easier (having articles under one page and reference them through the Page categories field), but can it be accomplished by keeping the structure above?

Link to comment
Share on other sites

If you keep the structure above, then you would consider the parent ($page->parent) to be the 'primary sub-category' and the grandparent ($page->parent->parent) to be the 'primary category'. In that case, you'd probably want to consider your categories page reference to be 'secondary categories'. I think this structure works fine if you consider the primary category/subcategory to be mostly static once published and more important than the secondary ones.

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...