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.

Tricky Category Menu Question

October 11, 2012 10:45pm

Subscribe [1]
  • #1 / Oct 11, 2012 10:45pm

    james Brown

    492 posts

    I have a pretty tricky categories tag question. Basically I’m wanting to create category menu for a blog that only shows a category in that menu if it is selected in a post that also has another specific category checked.

  • #2 / Oct 14, 2012 12:46pm

    Kevin Smith

    4784 posts

    Hi James,

    I’m not quite sure I follow. Could you give me an example of how this would look on your site?

  • #3 / Oct 16, 2012 11:15am

    james Brown

    492 posts

    I managed to solve it with a custom query. But I do have a question… Why is it so difficult to get a query inserted into an EE tag parameter? I ended up using this obscure plugin (see my code below). Is there an easier way?

    <ul>
    {exp:ab_entry_ids col_name="cat_id" sql="SELECT DISTINCT cat_id FROM exp_category_posts WHERE cat_id <> 106 AND entry_id in (SELECT entry_id FROM exp_category_posts WHERE cat_id = 106)"}
    {exp:channel:categories style="linear" channel="blog" show="{ab_entry_ids}"}
    <li><a href="/slic/blog/category/{category_url_title}">{category_name}</a></li>
    {/exp:channel:categories}
    {/exp:ab_entry_ids}
    </ul>
  • #4 / Oct 16, 2012 5:39pm

    Kevin Smith

    4784 posts

    It shouldn’t be difficult at all. If you wrap the Query tags around the Channel Categories tag and be smart about it (make sure the query is limited to a single response), then you should be able to just insert the result in the format of {col_name} within the Query tags. What were you trying that didn’t work?

  • #5 / Oct 16, 2012 5:45pm

    james Brown

    492 posts

    Well the main thing is that it isn’t a single response. As you can see in my query it will return all category id’s that meet that criteria. So when I was using the query module at first I was trying to put the entire query tag in the channel:categories show parameter. Of course that doesn’t work. But I could find an easy way to take my output of the query module and dump it into a parameter. Like I said, that add-on I am using does the trick… but isn’t super elegant.

  • #6 / Oct 17, 2012 2:27pm

    Kevin Smith

    4784 posts

    Glad to find out we’re sitting in the same room right now, James! With much thanks to Low for the tip here, try this instead:

    <ul>
    {exp:query sql="SELECT GROUP_CONCAT(DISTINCT cat_id SEPARATOR '|') cat_ids FROM exp_category_posts WHERE cat_id <> 106 AND entry_id in (SELECT entry_id FROM exp_category_posts WHERE cat_id = 106)"}
    {exp:channel:categories style="linear" channel="blog" show="{cat_ids}"}
    <li><a href="/slic/blog/category/{category_url_title}">{category_name}</a></li>
    {/exp:channel:categories}
    {/exp:query}
    </ul>

    That work?

  • #7 / Oct 17, 2012 2:31pm

    james Brown

    492 posts

    Thanks Kevin. I tried the suggestion with putting the entire {exp:query} tag in the parameter but changing the quotes and that worked as well. I probably should have realized that in the beginning! Thanks again for the help.

  • #8 / Oct 17, 2012 2:40pm

    Kevin Smith

    4784 posts

    No problem! I’m so glad we got this figured out.

    Have a good one.

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

ExpressionEngine News!

#eecms, #events, #releases