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.

displaying categories and entries... help?

August 11, 2010 12:12pm

Subscribe [3]
  • #1 / Aug 11, 2010 12:12pm

    meredithmarsh

    44 posts

    Feel free to move this if this isn’t considered support. I guess I’m trying to do something super complicated with categories and entires. I have categories and subcategories. Here http://yatesny.tempwebpage.com/dev/index.php/directory is the styled html example of that I want to occur. Below is the html of that I want to output.

    <ul id="alphabet">
                <li id="a"><span class="the_letter">A</span>
                    <ul class="letter_list">
                        <li>
                            <h3>Accounting</h3><p> <!-- category --><br />
                            <ul class="cat_list"><br />
                                <li class="listing_link"><a href="http://">Accounting Firm 1</a></li> <!-- {title} & permalink --><br />
                                <li class="listing_link"><a href="http://">Accounting Firm 2</a></li><br />
                                <li class="listing_link"><a href="http://">Accounting Firm 3</a></li><br />
                            </ul><br />
                        </li><br />
                        <li><br />
                            </p><h3>Animal Care</h3><p> <!-- category --><br />
                            <ul class="cat_list"><br />
                                <li class="sub_cat_list_item"></p><h4>Horse Training</h4><p> <!-- sub-category --><br />
                                    <ul class="sub_cat_list"><br />
                                        <li><a href="http://">Claynoll Stables, Clifton Springs</a></li><!-- {title} & permalink --><br />
                                    </ul><br />
                                </li><br />
                                <li class="sub_cat_list_item"></p><h4>Obedience School</h4><p> <!-- sub-category --><br />
                                    <ul class="sub_cat_list"><br />
                                        <li><a href="http://">K-9 Healers, Branchport</a></li><br />
                                        <li><a href="http://">Random Thing, Random Place</a></li><br />
                                    </ul><br />
                                </li><br />
                                <li class="sub_cat_list_item"></p><h4>Organic Animal Feed</h4><p> <!-- sub-category --><br />
                                    <ul class="sub_cat_list"><br />
                                        <li><a href="http://">Lakeview Organic Grain, Penn Yan</a></li><br />
                                        <li><a href="http://">Random Thing, Random Place</a></li><br />
                                    </ul><br />
                                </li><br />
                                <li class="sub_cat_list_item"></p><h4>Veterinarian</h4><p> <!-- sub-category --><br />
                                    <ul class="sub_cat_list"><br />
                                        <li><a href="http://">Eastview Veterinary Clinic, Penn Yan</a></li>                                                            <li><a href="http://">Random Thing, Random Place</a></li><br />
                                    </ul><br />
                                </li><br />
                            </ul><br />
                        </li><br />
                    </ul><br />
                </li> <!-- A --><br />
    </ul>

  • #2 / Aug 11, 2010 12:25pm

    Brad Morse

    428 posts

    Sorry for the vague response but this might give you the ability to accomplish this http://ellislab.com/forums/viewthread/81659

    It should list all categories, sub cats, and the entries assigned to them.

    If it does not, you would probably have to do some custom sql statement.

  • #3 / Aug 11, 2010 12:47pm

    meredithmarsh

    44 posts

    Thanks Brad. It looks promising but it’s only compatible with EE1.x at this point… road block! 😊

  • #4 / Aug 11, 2010 12:49pm

    Brad Morse

    428 posts

    Oops, this is a 2.x site? My bad. Or you’re keeping the potential of upgrading it to 2.x in mind?

  • #5 / Aug 11, 2010 12:51pm

    meredithmarsh

    44 posts

    It is 2.0 at this moment. So far I can’t see any reason for it not to be. Til now. Hehe.

  • #6 / Aug 11, 2010 1:02pm

    Boyink!

    5011 posts

    OK - basic approach.  Might need some added logic for correct markup:

    {exp:channel:categories channel="listings"}
      {category_name}
    
      {exp:channel:entries channel="listings" dynamic="no" category="{category_id}"}
         {if count==1}
             <ul>
         {/if}
    
         {entry_title}
    
         {if count==total_results}
           </ul>
         {/if}
        
      {/exp:channel:entries}
    
    {/exp:channel:categories}

    Not sure the markup will come out right - another idea is to pull the channel:entries tag into an embed.

  • #7 / Aug 11, 2010 1:13pm

    meredithmarsh

    44 posts

    Wow that did work! Make some adjustments but over all, that works. You make it look so easy! Thank you.

  • #8 / Aug 11, 2010 1:23pm

    Boyink!

    5011 posts

    Just make sure the list nesting is correct.  And use all the disable parameters you can on that inner channel:entries loop to reduce the number of queries.  Might also look at caching that template as well.

    Cheers!

  • #9 / Aug 11, 2010 1:35pm

    meredithmarsh

    44 posts

    The one thing I can’t figure out how to fix though: (screen shot attached). It’s listing the entry title below the category, and also below the sub category. I’d like it to list below sub cat only (if sub cat exists) and below cat only (if no subcat exists. Here’s my current code:

    {exp:channel:categories channel="business_directory" style="nested" class="letter_list"}
      <h3>{category_name}</h3>
    
    <p>  {exp:channel:entries channel="business_directory" dynamic="no" category="{category_id}"}<br />
         {if count==1}<br />
             <ul><br />
         {/if}</p>
    
    <p>     <a href="http://">{title}</a></p>
    
    <p>     {if count==total_results}<br />
           </ul><br />
         {/if}<br />
        <br />
      {/exp:channel:entries}</p>
    
    <p>{/exp:channel:categories}

    and here’s a link so it live. http://yatesny.tempwebpage.com/dev/index.php/directory the section in question is about mid-way down the very long page.

  • #10 / Aug 11, 2010 1:38pm

    Boyink!

    5011 posts

    Do you have “auto assign to parent category” turned on?

  • #11 / Aug 11, 2010 1:42pm

    meredithmarsh

    44 posts

    I did, now it’s set to off, still the same thing happens.

  • #12 / Aug 11, 2010 1:44pm

    Boyink!

    5011 posts

    Did you edit existing entries to remove the top-level category assignment?

  • #13 / Aug 11, 2010 1:52pm

    meredithmarsh

    44 posts

    Okay working beautifully now 😊 Thank you so much!

  • #14 / Aug 16, 2010 11:03am

    LucPestille

    146 posts

    It it an expected behavour that {count} and {total_results} are related to the category tag, rather than the channel tag inside it? The closing <ul> is never displayed for me…

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

ExpressionEngine News!

#eecms, #events, #releases