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.

Trouble displaying multiple entries under one category

February 21, 2012 12:06pm

Subscribe [2]
  • #1 / Feb 21, 2012 12:06pm

    rbboyl

    38 posts

    This may be a simple solution, but for some reason I can’t figure it out.  I have two entries that share the same category and I’m trying to get them to display in a nested unordered list (for navigation).

    When I use the code below, it lists the two entries separately and repeats the category name twice.

    <ul>
          <li><a href="http://{site_url}">Home</a></li>
          <li><a href="/about-us">About</a></li>
          <li><a href="#">Food</a>
           <ul>
           {exp:channel:entries channel="products" category_group="1" orderby="entry_id" dynamic="no"}
      {categories show="17|18|19|20|21"}
            <li><a href="#">{category_name}</a>
      <ul>
     
      <li><a href="/products/detail/{url_title}">{title}</a></li>
      
      </ul>
     </li>
     {/categories}
           {/exp:channel:entries}
           </ul>
          </li>

    The result I get is:
    Home
    About
    Food
    -Category 1
    —Entry 1
    -Category 1
    —Entry 2
    -Category 2
    —Entry 3
    -Category 2
    —Entry 4

    What I want is:
    Home
    About
    Food
    -Category 1
    —Entry 1
    —Entry 2
    -Category 2
    —Entry 3
    —Entry 4

     

  • #2 / Feb 22, 2012 12:58pm

    rbboyl

    38 posts

    Anybody?

  • #3 / Feb 22, 2012 2:14pm

    rbboyl

    38 posts

  • #4 / Feb 22, 2012 3:10pm

    Shane Eckert

    7174 posts

    Hello rbboyl,

    I am glad to see you found the answer!

    We try to get to these posts as fast as we can.

    I am pasting in the solution from stackoverflow just for reference.

    Cheers!

    Start Quote

    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.

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

ExpressionEngine News!

#eecms, #events, #releases