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.

List Entries by Categories

September 29, 2011 3:28pm

Subscribe [3]
  • #1 / Sep 29, 2011 3:28pm

    LW4 Comm

    16 posts

    Could someone please help me with this. I’m trying to show a list of questions and answers within each category. I have it working for the most part, but I can’t figure out how to group the questions and answers within the categories.

    For example,
    I’m getting:

    Career Opportunities
      question
      answer

    General Info
      question
      answer

    General Info
      question
      answer


    I would like to get:

    Career Opportunities
      question
      answer

    General Info
      question
      answer

      question
      answer

    Here’s the code I’ve tried:

    <h3 class="title">Frequently Asked Questions</h3>
      {exp:channel:categories channel="faq" orderby="date" sort="desc" disable="categories|member_data|trackbacks"}
       {exp:query sql="SELECT cat_id, group_id, cat_name, cat_url_title FROM exp_categories WHERE cat_url_title = '{category_url_title}'"}
    
        {exp:channel:entries channel="faq" category="{cat_id}"} 
        
         <h4>{category_name}</h4>
    <p>     <a href="http://{title_permalink=customer-service/faq-details}"><b>{faq_question}</b></a><br />
         {faq_answer}<br />
         <br />
        {/exp:channel:entries}<br />
        <br />
       {/exp:query} <br />
      {/exp:channel:categories}</p>
    
    <p>  <br>

    and also

    <h3 class="title">Frequently Asked Questions</h3>
      {exp:channel:categories channel="faq" status="open" style="linear" show_empty="no"}
    
       {exp:query sql="SELECT count(exp_category_posts.entry_id) AS post_count, field_id_127, field_id_128, exp_categories.cat_id FROM exp_category_posts 
        INNER JOIN exp_channel_data USING(entry_id) 
        INNER JOIN exp_categories USING(cat_id) 
        WHERE exp_category_posts.cat_id = {category_id} "}
    
        <h4>{category_name} ({post_count})</h4>
    <p>    <a href="http://{path=%27/customer-service/%27}" class="current"><b>{field_id_127}</b></a><br />
        {field_id_128}</p>
    
    <p>   {/exp:query}</p>
    
    <p>  {/exp:channel:categories}

  • #2 / Sep 30, 2011 2:42am

    John Henry Donovan

    12339 posts

    LW4 Comm,

    Take a look a the following article on nesting tags and performance in EE which also includes a nice example of what you are trying to achieve

    Does that help?

  • #3 / Sep 30, 2011 4:19pm

    LW4 Comm

    16 posts

    Sweet! That helps. Thanks a lot.

  • #4 / Oct 02, 2011 5:32pm

    Sue Crocker

    26054 posts

    Glad John was able to help. Don’t hesitate to post again as needed.

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

ExpressionEngine News!

#eecms, #events, #releases