Moderator’s note: Moved to Howto.
After several hours trying every trick I know, I’m now stumped and turn to you guys for help!
I’m on an entry listing page. I have a couple of dropdown menus which are populated by 2 different category groups. I want the visitor to be able to to choose from either, or both, of the dropdown menus and the resulting entries be filtered by the categories they chose.
I mostly have this down already. I’ve got the dropdown creating URL segments on the resulting page so I can reference them.
I’ve also used the wonderful Low Seg2Cat extension to translate the category short names in the URL to category ids.
I now need to use those category ids in the weblog:entries tag as a parameter, the basic idea being:
{exp:weblog:entries weblog="weblog" category="{segment_3_category_id}&{segment_4_category_id}"}At this point, this works a treat. It pops the correct category ids in the parameter and displays the correct entries.
Ok, here’s where it gets more complicated…
The 2 category dropdowns I have populating segment_3 and segment_4 also both have an ‘all’ option at the top of the list. Here’s actually what they are so you know what I’m talking about (stripped down to bare bones):
<!-- First dropdown -->
<select>
<option value="key">any key stage</option>
{exp:weblog:categories category_group="3" weblog="weblog" style="linear"}
<option value="{category_url_title}">{category_name}</option>
{/exp:weblog:categories}
</select><!-- Second dropdown -->
<select>
<option value="theme">any theme</option>
{exp:weblog:categories category_group="4" weblog="weblog" style="linear"}
<option value="{category_url_title}">{category_name}</option>
{/exp:weblog:categories}
</select>As you can see, I can’t just have a simple weblog:entries parameter like this…
category="{segment_3_category_id}&{segment_4_category_id}"}because if the first ‘segment_3’ dropdown has a value of “key” (i.e. ‘all’), and the second dropdown is a category, then I actually only want the category parameter to be this…
category="{segment_4_category_id}"}And vice versa, if the second ‘segment_4’ dropdown has a value of “theme” (i.e. ‘all’), and the first dropdown is a category, then I only want the category parameter to be this…
category="{segment_3_category_id}"}Further still, if both “key” and “theme” are chosen (i.e. no category) then there needs to be no parameter whatsoever!
I’ve tried various permutations of both native EE and PHP conditionals but nothing is working. I’d post up the various attempts I’ve made but this post is long enough already.
Am I over-complicating this? Any help or direction really appreciated. My head’s ready to pop.
Many thanks,
Dave