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.

Requiring 2 categories from different category groups in {exp:channel:entries category="20&50;"}

July 31, 2012 3:11am

Subscribe [2]
  • #1 / Jul 31, 2012 3:11am

    jaydisc

    19 posts

    I’m trying to only get entries that belong to TWO categories. The manual seems to indicate this is done as:

    category="3&7&8"

    Now, in my case, there are two category groups attached to this channel and I want to inclusively require one category from each of those category groups, but this does not seem to work. Am I doing something wrong, or is this not supported?

  • #2 / Jul 31, 2012 1:14pm

    Shane Eckert

    7174 posts

    Hey jaydisc,

    I am sorry to hear you are running into this problem.

    What results do you get? Do the posts from the categories not show? This should work.

    Can I see all your code for this template?

    Thank you,

  • #3 / Jul 31, 2012 7:11pm

    jaydisc

    19 posts

    Hi Shane,

    Thanks for the reply. Here’s some more specific background.

    In the “Tutorial” Channel Group Assignments, there are two category groups assigned. Here are those groups, and their categories:

    National Products:
    24 my_product_group
    25 my_other_product_group

    Options:
    65 Featured

    Now, the template group/ template is “product/series”. The URL I’m invoking is specifying the category for the “Series” channel (not to be confused with the above-described Tutorial channel). The “Series” Channel also has the National Products category group assigned to it.

    http://www.example.com/product/series/category/my_product_group

    All clear? Now let’s look at the relevant bits of that template:

    {embed="modules/_header"}
    <div class="content">
     {exp:channel:entries channel="series" limit="1" sort="asc"}
     <div class="row">
      <div class="span6">
       {if series_hero}{series_hero}{/if}
      </div>
      <div class="span10">
       {series_intro}
      </div>
     </div>
     {/exp:channel:entries}
     <div class="row">
      <div class="span8">
       <aside>
        <h1>Online Tutorials <small><a href="http://tutorials/">View All »</a></small></h1>
        {exp:channel:entries channel="tutorials" limit="1" sort="desc" category="65&24;"}
        <article>
         <h1>{entry_title}</h1>
         {entry_excerpt}
        </article>
        {/exp:channel:entries}
       </aside>
      </div>
     </div>
    </div>
    {embed="modules/_footer"}

    (P.S. There is no semicolon in my code after the 24. The interpreter here is sticking that in)

    Now, yesterday, I was wrong, and that channel:entries specifying 65&24; IS WORKING when hardcoded, but not dynamically as intended. Let me explain.

    Note that the first channel:entries tag, {exp:channel:entries channel="series"}, is NOT specifying a category, but is somehow magically aware of the category invoked in the URL and filters accordingly. (Is there a proper term to describe this kind of URL-invoked-category?)

    The goal of the second channel:entries tag (currently hardcoded to show {exp:channel:entries channel="tutorials" limit="1" sort="desc" category="65&24;"}), is to only load FEATURED entries in the category of my_product_group. As mentioned, when I hardcode it like that, it does work.

    But I want the 24 in that declaration to be dynamically discovered by the category specified in the URL. Is that possible? I can programatically discover the category_id from the URL using channel:category_heading tag, as such:

    {exp:channel:category_heading channel="series"}{category_id}{/exp:channel:category_heading}

    But I can’t inject that whole variable pair inside the category_id attribute of the entries tag like this:

    {exp:channel:entries channel="tutorials" limit="1" sort="desc" category="65{exp:channel:category_heading channel="series"}&{category_id}{/exp:channel:category_heading}”}

    So how can I incorporate the category ID invoked from the URL INTO the entries tag with the ADDITIONAL category_id of 65 being part of the requirement?

    Does that make sense?

  • #4 / Jul 31, 2012 9:04pm

    jaydisc

    19 posts

    It looks like I was able to solve this by nesting the entire template in {exp:channel:category_heading channel="series"} tags.
    And then, in the {exp:channel:entries channel=“tutorials”} tag, I could put:

    {exp:channel:entries channel="tutorials" limit="1" sort="desc" category="65&{category_id}"}

    Thanks for making me thing about it further. Is nesting an entire template in Category Heading tags acceptable protocol? Does it come with any known side effects?

     

  • #5 / Aug 01, 2012 12:45pm

    Shane Eckert

    7174 posts

    Hey jaydisc,

    If I am following this correctly, it looks good to me!

    You can turn on template debugging to see if there is any negative side effects, but I do not think there will be. Look at the queries and times.

    Thank you,

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

ExpressionEngine News!

#eecms, #events, #releases