title: Joomla k2 archive module sort by year and by month
body: <p>I'm using joomla with K2 and I want to order news in The archive module first by year. When you click on The year it Needs to show all articles from that year. Bit The module also Needs to expand The months to filter deeper</p>
  
  <p>How can I modify the module to act like This?</p>
  
  <p>Greets</p>
  
  <p>So this is what I mean</p>
  
  <p>2012
  - Januari
  - Februari
  - March
  - etc etc
  2013
  - Januari
  - Februari
  - March
  - etc etc.</p>
  
  <p>Both year and month needs to be filterable</p>
  
  <p>How can I modify the module to act like This?</p>
  
  <p>Greets</p>
  
  <p>So this is what I mean</p>
  
  <p>List item</p>
  
  <ul>
  <li>2012</li>
  <li>Januari</li>
  <li>Februari</li>
  <li>March</li>
  <li><p>etc etc </p></li>
  <li><p>2013</p>
  
  <ul>
  <li>Januari</li>
  <li>Februari</li>
  <li>March</li>
  <li>etc etc.</li>
  </ul></li>
  </ul>
  
  <p>Both year and month needs to be filterable</p>
  
  <p>How can I modify the module to act like This?</p>
  
  <p>Greets</p>
  
  <pre><code>&lt;div id="k2ModuleBox&lt;?php echo $module-&gt;id; ?&gt;" class="k2ArchivesBlock&lt;?php if($params-&gt;get('moduleclass_sfx')) echo ' '.$params-&gt;get('moduleclass_sfx'); ?&gt;"&gt;
    &lt;ul&gt;
      &lt;?php foreach ($months as $month): ?&gt;
      &lt;li&gt;
        &lt;?php if ($params-&gt;get('archiveCategory', 0) &gt; 0): ?&gt;
        &lt;a href="&lt;?php echo JRoute::_('index.php?option=com_k2&amp;view=itemlist&amp;task=date&amp;month='.$month-&gt;m.'&amp;year='.$month-&gt;y.'&amp;catid='.$params-&gt;get('archiveCategory')); ?&gt;"&gt;
          &lt;?php echo $month-&gt;name.' '.$month-&gt;y; ?&gt;
          &lt;?php if ($params-&gt;get('archiveItemsCounter')) echo '('.$month-&gt;numOfItems.')'; ?&gt;
        &lt;/a&gt;
        &lt;?php else: ?&gt;
        &lt;a href="&lt;?php echo JRoute::_('index.php?option=com_k2&amp;view=itemlist&amp;task=date&amp;month='.$month-&gt;m.'&amp;year='.$month-&gt;y); ?&gt;"&gt;
          &lt;?php echo $month-&gt;name.' '.$month-&gt;y; ?&gt;
          &lt;?php if ($params-&gt;get('archiveItemsCounter')) echo '('.$month-&gt;numOfItems.')'; ?&gt;
        &lt;/a&gt;
        &lt;?php endif; ?&gt;
      &lt;/li&gt;
      &lt;?php endforeach; ?&gt;
    &lt;/ul&gt;
  &lt;/div&gt;
  </code></pre>
  
  <p>The query is from another file</p>
  
  <pre><code>    public static function getArchive(&amp;$params)
  {
  
      $mainframe = JFactory::getApplication();
      $user = JFactory::getUser();
      $aid = (int)$user-&gt;get('aid');
      $db = JFactory::getDBO();
  
      $jnow = JFactory::getDate();
      $now = K2_JVERSION == '15' ? $jnow-&gt;toMySQL() : $jnow-&gt;toSql();
  
      $nullDate = $db-&gt;getNullDate();
  
      $query = "SELECT DISTINCT MONTH(created) as m, YEAR(created) as y FROM #__k2_items  WHERE published=1 AND ( publish_up = ".$db-&gt;Quote($nullDate)." OR publish_up &lt;= ".$db-&gt;Quote($now)." ) AND ( publish_down = ".$db-&gt;Quote($nullDate)." OR publish_down &gt;= ".$db-&gt;Quote($now)." ) AND trash=0";
      if (K2_JVERSION != '15')
      {
          $query .= " AND access IN(".implode(',', $user-&gt;getAuthorisedViewLevels()).") ";
          if ($mainframe-&gt;getLanguageFilter())
          {
              $languageTag = JFactory::getLanguage()-&gt;getTag();
              $query .= " AND language IN (".$db-&gt;Quote($languageTag).", ".$db-&gt;Quote('*').") ";
          }
      }
      else
      {
          $query .= " AND access&lt;={$aid} ";
      }
  
      $catid = $params-&gt;get('archiveCategory', 0);
      if ($catid &gt; 0)
          $query .= " AND catid=".(int)$catid;
  
      $query .= " ORDER BY created DESC";
  
      $db-&gt;setQuery($query);
      $rows = $db-&gt;loadObjectList();
      $months = array(JText::_('K2_JANUARY'), JText::_('K2_FEBRUARY'), JText::_('K2_MARCH'), JText::_('K2_APRIL'), JText::_('K2_MAY'), JText::_('K2_JUNE'), JText::_('K2_JULY'), JText::_('K2_AUGUST'), JText::_('K2_SEPTEMBER'), JText::_('K2_OCTOBER'), JText::_('K2_NOVEMBER'), JText::_('K2_DECEMBER'), );
      if (count($rows))
      {
  
          foreach ($rows as $row)
          {
              if ($params-&gt;get('archiveItemsCounter'))
              {
                  $row-&gt;numOfItems = modK2ToolsHelper::countArchiveItems($row-&gt;m, $row-&gt;y, $catid);
              }
              else
              {
                  $row-&gt;numOfItems = '';
              }
              $row-&gt;name = $months[($row-&gt;m) - 1];
              $archives[] = $row;
          }
  
          return $archives;
  
      }
  }
  </code></pre>