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 category.

February 02, 2012 9:20pm

Subscribe [4]
  • #1 / Feb 02, 2012 9:20pm

    Charming Nerd

    196 posts

    I am trying to organize my entries by category on the page. Basically I want the category archive tag, but I need to access my channel custom fields. Look at this page and you will see what I mean.


    http://67.199.23.35/tripcalendar/


    The categories are Service Adventures, Language Adventures etc. The listings in those categories are underneath.

    I need a way to dynamically loop through the categories, build that header, then list the entries underneath.

    I need it to be dynamic so my client have to edit the template.

    I don’t know enough php, but is it possible to loop through each category and display the listings and then move on to the next category.

    The categories you see are sub-categories of a parent category called Trip Types.

     

     

  • #2 / Feb 03, 2012 7:43am

    John St-Amand

    865 posts

    Yes, you can do that. You take a little bit of a performance hit in doing it though, but here’s how.  Just do away with the entry_titles tag pair and instead embed a channel:entries tag pair like this (resulting on one channel entries loop per category, which is why I warn you about performance):

    {exp:channel:category_archive channel="channel_name"}
        {categories}
                <h3>{category_name}</h3>
    <p>                                                     <br />
            {exp:channel:entries channel="channel_name" category="{category_id}"}<br />
                <a href="http://{title_permalink=PATH}">{title}</a><br />
                {some_custom_fields_here}<br />
            {/exp:channel:entries}</p>
    
    <p>    {/categories}<br />
    {/exp:channel:category_archive}

    In order to reduce the overhead of doing this, certainly you’d want to use the disable parameter liberally and keep the number you’re displaying reasonable, as this could become a pretty heavy page quickly, depending on the number of entries.

    Hope this helps.

  • #3 / Feb 03, 2012 1:21pm

    Charming Nerd

    196 posts

    Oh, so you just put the channel entries tag inside the archive tag. You saw the page it will be on, do you think it is too big for that? I would also be using cacheing so does it really matter? Won’t the page essentially be a static and get built every time a new entry is made?

    I also found this plugin last night. I like to stay away from plugin when I can do it natively, but In this case I need which ever gives me the options to build that page.

    http://devot-ee.com/add-ons/category-sorted-entries

  • #4 / Feb 03, 2012 2:05pm

    Laisvunas

    879 posts

    Hi,

    You can use Child Categories plugin.

  • #5 / Feb 03, 2012 2:51pm

    John St-Amand

    865 posts

    Charming, both of the plugins mentioned can definitely do the job and would reduce overhead undoubtedly. Your example page is not extremely heavy to begin with, so you’re probably in pretty good shape.  If you had a large number of categories it would be a more significant resource hog because with each category you’d get an entries loop.  Could go either way. Caching will certainly help as well, whether template or entries caching (or going the extra mile with caching add ons like CE Cache or Template Morsels - both of which I’ve used for significant performance gains).

    Cheers,
    John

  • #6 / Feb 03, 2012 3:18pm

    Charming Nerd

    196 posts

    I was planning on using CE Cache. I am going to test out the native method here in a bit and see what happens. Of course it will be faster being that I am developing locally, but there will never be hundreds of entries or anything.

  • #7 / Feb 03, 2012 3:23pm

    John St-Amand

    865 posts

    You ought to be OK going that way for sure, i would say.  You’ll certainly know based on the performance you see once you put it on your staging or live server.

    Cheers,
    John

  • #8 / Feb 08, 2012 6:36pm

    Charming Nerd

    196 posts

    I am finally coming back around to this. It works pretty well, but the archive tag isn’t very flexible when it comes to telling it which categories I want. I am attaching my category tree to illustrate. I only want the sub-categories of Trip Types. If I use show=“35” then it just lists them all with out displaying the category headings. If I use show=“not 38|37” it still lists all the sub-categories of each parent. I only want the sub-categories of Trip Types and I can’t explicitly list each category because they will change all the time. So, I have to use show=“35” but that just lists all the entries in that category.

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

ExpressionEngine News!

#eecms, #events, #releases