ExpressionEngine CMS
Open, Free, Amazing

Thread

This is an archived forum and the content is probably no longer relevant, but is provided here for posterity.

The active forums are here.

Complex Category Queries

November 07, 2011 7:58pm

Subscribe [2]
  • #1 / Nov 07, 2011 7:58pm

    BrettWagner

    9 posts

    I currently have a couple of category groups that look like this:

    Category 1 ‘project types’:
      - cat 1: project type one
      - cat 2: project type two
      - cat 3: project type three
      - cat 4: project type four
    Category 2 ‘featured’:
      - cat 5: Featured

    So I have a channel full of projects that have various categories assigned.

    I want to display them on will contain a section where I show the featured projects for a project type and then below for others.  So roughly my page currently looks like this:

    FEATURED
    {exp:channel:entries channel="project" category="1&5" dynamic="off" orderby="client_name" sort="asc"}
    >RENDER<
    {/exp:channel:entries}

    OTHER
    {exp:channel:entries channel="project" category="1" dynamic="off" orderby="client_name" sort="asc"}
    >RENDER WITH SWITCH FOR COLUMNS<
    {/exp:channel:entries}

    Now obviously the ‘other’ section is currently broken, it’s displaying all the projects of type 1.  I’ve tried setting category=‘1 not 5’.. this doesn’t seem to work. 

    So my frist question is, does it actually work and am I missing some other bug?

    My current solution is a hodgepodge of php that checks the categories for the featured categories and selectively does not render them, the problem is that this screws up {switch} for my multi column layout… so I could go deeper down this road its more php which is fine, but ugly and harder to maintain.

    I guess I could go to the query plugin to create my more complicated query, but again, lowers maintainability.

    My followup questions are:
    1) is there a preferred way to make this work?
    2) is there some way to do a sub query on a returned entries recordset?

  • #2 / Nov 08, 2011 8:25pm

    Sean C. Smith

    3818 posts

    Hi BrettWagner,

    In each of your exp:channel:entries tags could you add the parameter category_group=”“ with the correct category group id.

    Try that and then let me know how it goes.

    Sean

  • #3 / Nov 17, 2011 7:36pm

    BrettWagner

    9 posts

    I’m confused ( and got busy chasing other things ).

    So… I’m not sure how category_group=”” helps here.

    I’m looking for a variation of this
    {exp:channel:entries channel=“project” category=“1” dynamic=“off” orderby=“client_name” sort=“asc”}

    where the projects are in category 1 but NOT ALOS in category 5.

    edit:
    I just tried:
    {exp:channel:entries channel=“project” category=“1” category_group="not 2" dynamic=“off” orderby=“client_name” sort=“asc”}

    to no avail, things that are tagged with both 1(in group 1) and 5(in group 2) are still appearing.

  • #4 / Nov 18, 2011 5:49pm

    Sean C. Smith

    3818 posts

    BrettWagner,

    I see now what you want to to do - it became clearer after reading your final sentence in the latest post. Unfortunately when limiting to categories the channel entries tag will display the entries if an entry is in any or all of the categories. I would suggest that you see if there is an add-on that will help you out. Looking on Devot-ee for Categories returns many results.

    Sean

.(JavaScript must be enabled to view this email address)

ExpressionEngine News!

#eecms, #events, #releases