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.

group channel entries by month then by category

October 10, 2011 7:08pm

Subscribe [1]
  • #1 / Oct 10, 2011 7:08pm

    triplicate

    4 posts

    Hi everyone,

    I’m trying to group my channel entries first by month and then by category. So basically I need a title for the month/year and then inside that, a sub title for each category, under which the entries will be listed.

    I’ve searched the web and the closest thing I could find was this tutorial on loweblog.

    I managed to modify this slightly to group my entries by month and year, but I’m not sure how to group this by category. My code is shown below.

    I’m new to expression engine, so not sure if this is bit overkill, or if there’s a native ee feature that I could use in this situation.

    <?php 
    $entries = array();
    {exp:channel:entries channel="updates" dynamic="no" disable="member_data|pagination|category_fields" show="not 27|26"}
    
     $entry = array(
      'title' => "{title}",
      'file' => "{update_file}",
      'category' => "{categories show="not 27|26"}{category_name}{/categories}"
     );
    
     $entries['{date_heading}{entry_date format="%M %Y"}{/date_heading}'][] = $entry;
    {/exp:channel:entries}
    
    
    echo "<pre>";
     print_r($entries);
    echo "</pre><p>“;<br />
    ?>
    </pre>

    Array
    (
        [Oct 2011] => Array
            (
                [0] => Array
                    (
                        [title] => CAD Drawing Updates
                        [file] => gm-June2010-driver.pdf
                        [category] => Windows
                    )
            )
    
        [Sep 2011] => Array
            (
                [0] => Array
                    (
                        [title] => fucking work
                        [file] => gm-June2010-driver.pdf
                        [category] => Windows
                    )
                [1] => Array
                    (
                        [title] => edges
                        [file] => gm-June2010-driver.pdf
                        [category] => Curtain Walling
                    )
                [2] => Array
                    (
                        [title] => Specification update
                        [file] => gm-June2010-driver.pdf
                        [category] => Windows
                    )
            )
    )
  • #2 / Oct 11, 2011 4:57am

    triplicate

    4 posts

    ended up with this, groups the entries by month/year and then by category, and we can still use paginate.

    <?php 
     $entries = array();
    ?>
    
    {exp:channel:entries channel="updates" disable="member_data|category_fields" show="not 27|26" paginate="bottom" limit="10"}
    
     <?php 
     $entry = array(
      'title' => "{title}",
      'file' => "{update_file}",
      'category' => "{categories show="not 27|26"}{category_name}{/categories}"
     );
    
     $entries['{date_heading}{entry_date format="%M %Y"}{/date_heading}']['{categories show="not 27|26"}{category_name}{/categories}'][] = $entry;
     ?> 
    
     
     {paginate}
      <h1>page {current_page}</h1>
     {/paginate} 
     
     
    {/exp:channel:entries}
    
    
    
    
    <?php
    echo "<pre>";
     print_r($entries);
    echo "</pre><p>“;<br />
    ?>
    </pre>

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

ExpressionEngine News!

#eecms, #events, #releases