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.

exp:query - don´t show empty category

July 01, 2007 11:31am

Subscribe [0]
  • #1 / Jul 01, 2007 11:31am

    Geri

    2 posts

    Hi there!

    Hoping, someone can give me a hint.

    I´m using following query within an weblog:entries tag, to show subcategories. That works fine so far:

    {exp:query sql="SELECT cat_name AS sub_cat_name, cat_id AS sub_cat_id FROM exp_categories WHERE parent_id = '5' AND group_id = '1'"}

    But I want to show only subcategories with 1 entry at least. Analogue to

    show_empty="no"

    parameter in weblog:categories tag.

    Guess, I need an additional “WHERE AND ????”. But what? Or do i need an INNERJOIN or something else? Note: The query is already running within an weblog:entries tag.

    Anyone with a quick and dirty approach to that?

    Thanks, Geri

  • #2 / Jul 01, 2007 11:54am

    Robin Sowell

    13255 posts

    You’ll need to join the exp_category_posts table, which is easy to do.  But I’m fuzzy on why this needs to be nested inside a weblog tag- and it’s something I’d avoid doing on a multi-entry page if at all possible.

    Can you lay out the full code you’re using to do this- and why it needs to be nested?

  • #3 / Jul 01, 2007 7:35pm

    Geri

    2 posts

    But I’m fuzzy on why this needs to be nested inside a weblog tag- and it’s something I’d avoid doing on a multi-entry page if at all possible.

    Ok Robin, I´ll try to explain:

    My first thing was following code, OUTSIDE the weblog tag:

    {exp:weblog:category_heading weblog="{my_weblog}"}
    <h2>{category_name}</h2>
    <p>{if category_description}{category_description}{/if}</p>
    
    <p>{exp:query sql="SELECT cat_name AS sub_cat_name, cat_id AS sub_cat_id FROM exp_categories WHERE parent_id = '{category_id}' AND group_id = '1'"}<br />
    (<a href="http://{path={my_template_group}/C{sub_cat_id}}">{sub_cat_name}</a>) <br />
    {/exp:query}</p>
    
    <p>{/exp:weblog:category_heading}

    Then I realised, that everybody who put any category-number in the URL will see the category header (if category exists), regardless what weblog and category. So you have only try all numbers through and you´ll see all named categories. I want to avoid that.

    So I moved the above code into the webglog tag and embeded it into a {if category_request AND count == 1} pair. I think, it´s not really good practice. But now, it will show only category headers who belongs to the assigned weblog.

    That is the reason, why I nested it into the weblog tag. Do you have a better idea?
    And how would you build up the query (quick and dirty) to sort out empty categories?
    (I´m not a newbie to SQL but really not a geek)

    Thanks for your reply,
    Geri

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

ExpressionEngine News!

#eecms, #events, #releases