Displaying entries per category in ExpressionEngine
Asked Answered
P

3

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!

Proteinase answered 10/1, 2011 at 1:28 Comment(0)
P
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.

Proteinase answered 28/1, 2011 at 15:55 Comment(0)
U
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}
Uhland answered 26/1, 2011 at 21:14 Comment(3)
Yeah, that's the basic version of what I ended up with. I've created another answer to demonstrate what I finally used.Proteinase
you saved a strand of my sanity tonight, thank you for posting.Dorthadorthea
This example works when you add dynamic="no" to your channel:entries tag.Tutuila
P
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.

Proteinase answered 28/1, 2011 at 15:55 Comment(0)
M
1

The Category Archive tag might be helpful to you:

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

Marbleize answered 11/2, 2014 at 1:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.