5

So, I've searched, and found a few posts that kinda get me what I want, but it still doesn't quite work. This post especially seemed closest to what I was trying to achieve, and I built my code off of it: http://expressionengine.com/forums/viewthread/168142/

To explain; I have a series of entries, each entry is assigned to only one category. I'd like to list out these categories and, beneath each category, list out the entries with one of their custom fields. Like so:

  • Category 1

    • Item 1
    • Item 2
  • Category 2

    • Item 1
    • Item 2

So, here's my code as it stands now, which lists out the categories, but doesn't spit out any of the entries at all:

{exp:channel:categories channel="faq-question" style="linear"}
    <section class="faq-category-container closed">
        <h1 class="faq-category-header"><a href="#">{category_name}</a></h1>
        <dl>
    {exp:query sql="

        SELECT title, url_title AS urlt, cat_id

        FROM exp_channel_titles

        NATURAL JOIN exp_category_posts

        WHERE channel_id = '7' AND cat_id = '{category_id}'

        ORDER BY title ASC"
    }
        {embed="jazz-camp/faq-cat-list" faqlink="{urlt}"}
    {/exp:query}
        </dl>
    </section><!-- end .faq-category -->
{/exp:channel:categories}

And the embedded template it references:

{exp:channel:entries channel="faq-question" url_title="{embed:faqlink}"}<!-- entry -->
    <dt>{title}</dt>
    <dd>
        {faq_content}
    </dd>
{/exp:channel:entries}

Any help would be most appreciated!

3 Answers 3

14

This may be a very basic example of what you're after:

{exp:channel:categories style="linear"}
  <h1>{category_name}:</h1> 
  {exp:channel:entries category="{category_id}" dynamic="no"}
    <p>{my_custom_field}</p>
  {/exp:channel:entries}
{/exp:channel:categories}
3
  • Yeah, that's the basic version of what I ended up with. I've created another answer to demonstrate what I finally used.
    – jeffbyrnes
    Jan 28, 2011 at 15:50
  • you saved a strand of my sanity tonight, thank you for posting.
    – Julian
    Jun 22, 2012 at 7:22
  • 1
    This example works when you add dynamic="no" to your channel:entries tag.
    – Joan
    Dec 11, 2013 at 13:12
5

So, here's what I ended up with at the end (courtesy of some help over at the EE boards):

{exp:channel:categories channel="faq-camp" style="linear" show_empty="no"}
    <section class="faq-category-container closed">
        <h1 class="faq-category-header"><a href="#">{category_name}</a></h1>
        <div class="faq-questions-container">
            <dl>
    {embed="jazz-camp/faq-cat-list" faqlink="{category_id}" faqparent="faq-camp"}
            </dl>
        </div><!-- end .faq-questions-container -->
    </section><!-- end .faq-category -->
{/exp:channel:categories}

And as for the embed, it looks like this:

{exp:channel:entries channel="{embed:faqparent}" category="{embed:faqlink}" dynamic="no"}<!-- entries -->
    <dt>{title}</dt>
    <dd>
        {faq_answer}
    </dd>
{/exp:channel:entries}

The reason for the embed has to do with how things are pulled in with regards to getting the correct channel entries; simply having the {exp:channel:entries} inline in the page didn't quite work.

1

The Category Archive tag might be helpful to you:

http://ellislab.com/expressionengine/user-guide/modules/channel/category_archive.html

Your Answer

Reminder: Answers generated by Artificial Intelligence tools are not allowed on Stack Overflow. Learn more

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.