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.

query inside weblog:entries tag

August 06, 2010 7:40pm

Subscribe [1]
  • #1 / Aug 06, 2010 7:40pm

    petattlebaum

    60 posts

    Hello,
    The short version:
    Can you place an exp:query inside a weblog:entries tag?

    Here’s what I’m trying to do.

    I have two templates; menu and page.  The menu embeds in the page template.  In past weblogs everything has worked great in that the correct menu entries that are related to the main content on the page template appear.

    However, for my new weblog I’m using categories AND subcategories. The catch? 
    Auto-Assign Category Parents is set to Yes.

    So because I’m using subcategories, I think I need to use a query so that on subcategory pages, the subcategory and NOT the category menu appears.

    Below is code I’ve used in the past that works great for working with only parent categories:

    {if segment_2 == 'entry'}
                    {exp:weblog:entries weblog="eeos"}
                                    {categories}{if category_id == '486'}{/categories}
                                                    <ul>
                                                    {embed="eeos/menu_embed" catg="486"}
                                                    </ul>
                                    {categories}{if:elseif category_id == '487'}{/categories}
                                                    <ul>
                                                                    <li> <a href="http://{path=">Undergraduate Program</a></li>     
                                                                    {embed="eeos/menu_embed" catg="487"}
                                                    </ul>

    I didn’t paste all the code.

    However, now I have entries that are listed twice in the category_posts table, with for example entry id 2203 is listed with cat_id 486 and 490 (this being the subcategory).

    Can i, with Auto-Assign Category Parents is set to Yes, use code similar to the code above, to list entries in only the subcategory?

    Thanks!

  • #2 / Aug 06, 2010 8:14pm

    petattlebaum

    60 posts

    Darn, I thought I had it with this code below but it didn’t work.
    cat_id 490 is the parent category
    cat_id 499 is the sub category

    with only if cat_id == ‘490’ it works.
    But with only if cat_id == ‘499’ and the code below it doesn’t.

    So close.  Any help is appreciated.

    {exp:query sql="SELECT e.entry_id, e.cat_id, e1.entry_id, e1.weblog_id, e1.title, e1.url_title FROM exp_eng.exp_weblog_titles e1, exp_eng.exp_category_posts e WHERE e1.weblog_id = 104 AND e.entry_id = e1.entry_id AND e.cat_id = 490 OR e.cat_id = 499 GROUP BY e.entry_id HAVING COUNT(*) = 1;"}
    {if cat_id == '490' AND cat_id == '499'}
                                                                    <li><a href="/eeos/entry/{url_title}">{title} - {cat_id}</a></li>
    {/if}
                                                                    {/exp:query}
  • #3 / Aug 07, 2010 2:01am

    petattlebaum

    60 posts

    OK, I was way off…you knew that.  Turns out that ” at the end of a query really is needed.
    Duh!

    So, obviously the exp:query code in my above post wasn’t close to working.

    Question.  Is there a weblog:entries tag equivalent to SQL’s Group BY…HAVING COUNT?
    My thinking is that if there is, I can use that could within an if conditional inside the menu_embed templates.

    {if segment_2 == 'entry'}
        {exp:weblog:entries weblog="eeos"}
              {categories}{if category_id == '490'}{/categories}
                 <ul>
                    {embed="eeos/menu_embed" catg="490"}
                 </ul>
              {categories}{if:elseif category_id == '499'}{/categories}
                 <ul>
                    {embed="eeos/menu_embed" catg="499"}
                 </ul>


    the menu_embed code is:

    {exp:weblog:entries weblog="eeos" category="{embed:catg}" disable="member_data|trackbacks" dynamic="off" orderby="title" sort="asc"}
    <li> <a href="http://{path=">{title}</a></li>           
    {/exp:weblog:entries}

    Am I even close to being on the right track?

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

ExpressionEngine News!

#eecms, #events, #releases