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.

Order entrys by date but group in categories...

September 28, 2011 4:08am

Subscribe [6]
  • #1 / Sep 28, 2011 4:08am

    This is probably very simple, and I dare say I just need more caffeine to get some more grey matter working…!

    I’m creating a tumblelog from all my feeds around the web, along with my EE based blog posts. It’s all coming along very well, but I’m struggling to work out how to achieve my desired end result.

    What I want to have is a flow of all my content, ordered by date BUT it also needs to be grouped by categories.

    So this months posts would have a daily/monthly date heading eg “September ‘09”, then the entries are grouped by category, eg flickr, dribbble, vimeo etc.

    My current basic markup is as follows:

    {exp:channel:entries channel="tumblelog" orderby="date" disable="member_data|pagination" category="11|2|7|50"}
      {date_heading display="monthly"}       
      <h1>{entry_date format="%F %y"}</h1>       
      {/date_heading}
      {title}      
      {/exp:channel:entries}

    Any thought appreciated, I’m ready to slap myself on the forehead and sit in the corner for a while too 😉

     

  • #2 / Sep 28, 2011 4:00pm

    John St-Amand

    865 posts

    What takes priority - the category grouping or the date grouping?  Are you looking for groupings within each category INSIDE each monthly date heading?  what if you only had one entry in a given category within a given month?  The category heading might look a bit “off”.

  • #3 / Sep 29, 2011 4:13am

    Hi John,

    I guess the most important is to arrange posts by month first, then group by category. So Yes Iam looking to group each category inside each month date heading.

    Based on my markup above here’s my test URL - http://dev.paulcripps.com/default/archive you’ll get the idea of what I’m trying to achieve.

  • #4 / Sep 30, 2011 3:53am

    nathanpitman

    531 posts

    If I’m right what you are trying to do is display everything in date order but when you have two or three items from one source beside it other, ‘wrap’ them in a div so they can appear to be grouped?

    I think you would have to do this with some post processing in the template, ie spit everything out in date order and on each loop of the channel:entries tag check for which group an item belongs to, assign this to a variable and open the wrapper div, keep cycling through rows until the group changes and at that point close the div and open another one for the next group. You would then add a final closing div at the bottom of the loop to make sure the final group is always closed.

    😊

  • #5 / Sep 30, 2011 4:05am

    Darren Miller

    103 posts

    Am I allowed to suggest a custom add on?

    1. Single query to get all the data you need to display from the channel tables. If only one category is assigned to each entry you can grab category data at the same time.

    2. Prepare an empty array to store entries

    2. Loop results. If multiple categories per entry, grab them now.

    3. Populate your results array using months and category names as key values. You make these on the fly using entry_date and category_name. So you’d have

    Array(
      'September 2011' => 
       Array (
          'Category Heading' => Array ([entry],[entry],[entry])
          'Category Heading2' => Array ([entry],[entry],[entry])
       ),
       'August 2011' =>
       Array (
          'Category Heading' => Array ([entry],[entry],[entry])
          'Category Heading2' => Array ([entry],[entry],[entry])
       ),
       ... and so on
    )

    You might have some fun with sorting. If the date key value was a timestamp that would help.

    4. Now do another loop over the above array and parse it out into your template tagdata

  • #6 / Sep 30, 2011 4:10am

    Laisvunas

    879 posts

    Hi Paul,

    Try Entries List plugin. This plugin has parameter “sort_separately” which accepts the value “categories”.

  • #7 / Sep 30, 2011 4:16am

    Thanks for the feedback everyone,

    @nathanpitman - close, what I’m after is entries grouped by month, then all grouped by category eg social network, so lets say for September you get all entries, then all of the flickr ones grouped together.

    @darrenmiller - thank you - going to try @laisvunas plugin first, then I’ll try your method.

    @laisvunas - thank you - it sounds like that plugin should help me 😊

  • #8 / Sep 30, 2011 4:36pm

    @laisvunas

    What would be the best way to use this plugin in conjunction with the following:

    {exp:channel:entries channel="tumblelog" orderby="date" disable="member_data|pagination" category="11|2|7|50"}
      {date_heading display="monthly"}       
      <h1>{entry_date format="%F %y"}</h1>       
      {/date_heading}
      {title}      
      {/exp:channel:entries}

    It looks like the plugin would work for the category listings, BUT I want to output entries archived by month first then grouped by categories.

    I’m having a bit of a fail on this one.

  • #9 / Sep 30, 2011 7:20pm

    e-man

    1816 posts

    Have a look at this article by @low http://loweblog.com/freelance/article/nesting-tags-and-performance-in-ee/
    I think that’ll put you on the right path.
    http://ellislab.com/expressionengine/user-guide/modules/channel/category_archive.html
    will output your entries sorted by category, I’m sure there’s a way to combine this with sorting them by month in a channel:entries loop.

  • #10 / Oct 01, 2011 10:57am

    Laisvunas

    879 posts

    Hi Paul,

    In order to output entries archived by month first then grouped by categories the plugin Entries List needs a couple of additional parameters. I will consider this problem next week and will update you.

  • #11 / Oct 03, 2011 6:46am

    Laisvunas

    879 posts

    Hi Paul,

    Download the version 4.1 of Entries List plugin. In this version 2 new parameters were added: “entries_start_on” and “entries_stop_before”. Using them you can output entries archived by month first then grouped by categories. The code would be as this:

    <h1>January 2011</h1>
    {exp:entries_list channel="tumblelog" orderby="date" category="11|2|7|50" sort_separately="categories" entries_start_on="2011-01-01 00:00" entries_stop_before="2011-02-01 00:00" date_format="%Y-%m-%d %h-%i %A"}
    {title}, {category_name}, {entries_list_entry_date}
    
    
    {/exp:entries_list}
    
    <h1>February 2011</h1>
    {exp:entries_list channel="tumblelog" orderby="date" category="11|2|7|50" sort_separately="categories" entries_start_on="2011-02-01 00:00" entries_stop_before="2011-03-01 00:00" date_format="%Y-%m-%d %h-%i %A"}
    {title}, {category_name}, {entries_list_entry_date}
    
    
    {/exp:entries_list}
    
    <h1>March 2011</h1>
    {exp:entries_list channel="tumblelog" orderby="date" category="11|2|7|50" sort_separately="categories" entries_start_on="2011-03-01 00:00" entries_stop_before="2011-04-01 00:00" date_format="%Y-%m-%d %h-%i %A"}
    {title}, {category_name}, {entries_list_entry_date}
    
    
    {/exp:entries_list}
  • #12 / Oct 03, 2011 4:49pm

    @laisvunas this looks like it might work..

    I’ve tried embedding this withing an outer entries tag and or a date heading tag but its outputting some odd results (granted I’ve had a long day and its late, so I may well slap my head in the morning..!)

    So how would you dynamically generate the entries_start_on and entries_stop_before dates?

    What would be great is if it worked by of having pair date heading tags as you can with entries tag:
     
    {date_heading display="monthly"}   
    <h1>{entry_date format="%F %y"}</h1>   
    {/date_heading}

    Really appreciate you help on this one 😊

  • #13 / Oct 04, 2011 3:15am

    Laisvunas

    879 posts

    Hi Paul,

    To dynamically generate the entries_start_on and entries_stop_before dates you need to create a new snippet. Go CP Home > Design > Template Manager > Snippets, enter as Snippet name “current_year” and as Variable Content this code:

    {current_time format="%Y"}

    Then change the code of my previous post this way:

    {exp:entries_list channel="tumblelog" orderby="date" category="11|2|7|50" sort_separately="categories" entries_start_on="{current_year}-01-01 00:00" entries_stop_before="{current_year}-02-01 00:00" date_format="%Y-%m-%d %h-%i %A"}
    {if entries_list_count == 1}<h1>{entries_list_entry_date date_format="%F %Y"}</h1>{/if}
    {title}, {category_name}, {entries_list_entry_date}
    
    
    {/exp:entries_list}
    
    {exp:entries_list channel="tumblelog" orderby="date" category="11|2|7|50" sort_separately="categories" entries_start_on="{current_year}-02-01 00:00" entries_stop_before="{current_year}-03-01 00:00" date_format="%Y-%m-%d %h-%i %A"}
    {if entries_list_count == 1}<h1>{entries_list_entry_date date_format="%F %Y"}</h1>{/if}
    {title}, {category_name}, {entries_list_entry_date}
    
    
    {/exp:entries_list}
    
    {exp:entries_list channel="tumblelog" orderby="date" category="11|2|7|50" sort_separately="categories" entries_start_on="{current_year}-03-01 00:00" entries_stop_before="{current_year}-04-01 00:00" date_format="%Y-%m-%d %h-%i %A"}
    {if entries_list_count == 1}<h1>{entries_list_entry_date date_format="%F %Y"}</h1>{/if}
    {title}, {category_name}, {entries_list_entry_date}
    
    
    {/exp:entries_list}

     

  • #14 / Oct 04, 2011 7:07am

    Hi Laisvunas,

    Sorry I think I’ve confused things a little. Not sure, let me explain…

    I’m after a complete archive, for all posts from today all the way back to my fist post. I’ve setup a section “tumblelog” allowing me to post a traditional blog post and it automatically pulls all my feeds from flickr, twitter etc.

    The page should work as a complete flow, from today all the way back to my first ever post. To give you an idea take a look at http://dev.paulcripps.com/archive

    So all of the date tags need to be generated automatically, which is why I was using the following monthlly archive markup:

    {exp:channel:entries channel="tumblelog" orderby="date" disable="member_data" limit="40" paginate="bottom"}
    
    {date_heading display="monthly"}       
    <h1>{entry_date format="%F %y"}</h1>
    {/date_heading}
    
    <div id="e{entry_id}">  
     {image_url}
     {title}
    </div>
    
    {paginate}
    <div> 
    Page {current_page} of {total_pages} pages {pagination_links}  
    </div>
    {/paginate}
        
    {/exp:channel:entries}

    In an ideal worlds I’d use your plugin but simply pass it the month and year only. Then it should return the entries for the given month grouped by category.

    My problem is, using hardcoded years or months simply will not work as it needs to run as a complete archive for all years and months.

    The more I think about it the more I think a custom query or to build my own plugin is going to be the only way to resolve this.

  • #15 / Oct 04, 2011 7:48am

    Laisvunas

    879 posts

    Hi Paul,

    If you need to display archive for several years, then you need to hardcode only the year you submitted your first entry (let’s say it was 2009). You would be using free Loop Plus plugin:

    {exp:loop_plus start="2009" end="{current_year}" increment="1" parse="inward"}
    {exp:entries_list channel="tumblelog" orderby="date" category="11|2|7|50" sort_separately="categories" entries_start_on="{index}-01-01 00:00" entries_stop_before="{index}-02-01 00:00" date_format="%Y-%m-%d %h-%i %A"}
    {if entries_list_count == 1}<h1>{entries_list_entry_date date_format="%F %Y"}</h1>{/if}
    {title}, {category_name}, {entries_list_entry_date}
    
    
    {/exp:entries_list}
    
    {exp:entries_list channel="tumblelog" orderby="date" category="11|2|7|50" sort_separately="categories" entries_start_on="{index}-02-01 00:00" entries_stop_before="{index}-03-01 00:00" date_format="%Y-%m-%d %h-%i %A"}
    {if entries_list_count == 1}<h1>{entries_list_entry_date date_format="%F %Y"}</h1>{/if}
    {title}, {category_name}, {entries_list_entry_date}
    
    
    {/exp:entries_list}
    
    {exp:entries_list channel="tumblelog" orderby="date" category="11|2|7|50" sort_separately="categories" entries_start_on="{index}-03-01 00:00" entries_stop_before="{index}-04-01 00:00" date_format="%Y-%m-%d %h-%i %A"}
    {if entries_list_count == 1}<h1>{entries_list_entry_date date_format="%F %Y"}</h1>{/if}
    {title}, {category_name}, {entries_list_entry_date}
    
    
    {/exp:entries_list}
    {/exp:loop_plus}

     

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

ExpressionEngine News!

#eecms, #events, #releases