-2

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

How can I modify the module to act like This?

Greets

So this is what I mean

2012 - Januari - Februari - March - etc etc 2013 - Januari - Februari - March - etc etc.

Both year and month needs to be filterable

How can I modify the module to act like This?

Greets

So this is what I mean

List item

  • 2012
  • Januari
  • Februari
  • March
  • etc etc

  • 2013

    • Januari
    • Februari
    • March
    • etc etc.

Both year and month needs to be filterable

How can I modify the module to act like This?

Greets

<div id="k2ModuleBox<?php echo $module->id; ?>" class="k2ArchivesBlock<?php if($params->get('moduleclass_sfx')) echo ' '.$params->get('moduleclass_sfx'); ?>">
  <ul>
    <?php foreach ($months as $month): ?>
    <li>
      <?php if ($params->get('archiveCategory', 0) > 0): ?>
      <a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&task=date&month='.$month->m.'&year='.$month->y.'&catid='.$params->get('archiveCategory')); ?>">
        <?php echo $month->name.' '.$month->y; ?>
        <?php if ($params->get('archiveItemsCounter')) echo '('.$month->numOfItems.')'; ?>
      </a>
      <?php else: ?>
      <a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&task=date&month='.$month->m.'&year='.$month->y); ?>">
        <?php echo $month->name.' '.$month->y; ?>
        <?php if ($params->get('archiveItemsCounter')) echo '('.$month->numOfItems.')'; ?>
      </a>
      <?php endif; ?>
    </li>
    <?php endforeach; ?>
  </ul>
</div>

The query is from another file

    public static function getArchive(&$params)
{

    $mainframe = JFactory::getApplication();
    $user = JFactory::getUser();
    $aid = (int)$user->get('aid');
    $db = JFactory::getDBO();

    $jnow = JFactory::getDate();
    $now = K2_JVERSION == '15' ? $jnow->toMySQL() : $jnow->toSql();

    $nullDate = $db->getNullDate();

    $query = "SELECT DISTINCT MONTH(created) as m, YEAR(created) as y FROM #__k2_items  WHERE published=1 AND ( publish_up = ".$db->Quote($nullDate)." OR publish_up <= ".$db->Quote($now)." ) AND ( publish_down = ".$db->Quote($nullDate)." OR publish_down >= ".$db->Quote($now)." ) AND trash=0";
    if (K2_JVERSION != '15')
    {
        $query .= " AND access IN(".implode(',', $user->getAuthorisedViewLevels()).") ";
        if ($mainframe->getLanguageFilter())
        {
            $languageTag = JFactory::getLanguage()->getTag();
            $query .= " AND language IN (".$db->Quote($languageTag).", ".$db->Quote('*').") ";
        }
    }
    else
    {
        $query .= " AND access<={$aid} ";
    }

    $catid = $params->get('archiveCategory', 0);
    if ($catid > 0)
        $query .= " AND catid=".(int)$catid;

    $query .= " ORDER BY created DESC";

    $db->setQuery($query);
    $rows = $db->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->get('archiveItemsCounter'))
            {
                $row->numOfItems = modK2ToolsHelper::countArchiveItems($row->m, $row->y, $catid);
            }
            else
            {
                $row->numOfItems = '';
            }
            $row->name = $months[($row->m) - 1];
            $archives[] = $row;
        }

        return $archives;

    }
}
WNR Design
  • 105
  • 1
  • 2
  • 13
  • This does not give us much to go on how about posting some code. In your case data is being pulled from database table simply output all articles from given year by changeing the database query. And then you can sort the array by months before printing it ouy. Still tho your question is pretty unclear and with no code to present the problem. – Sterling Duchess Nov 15 '12 at 17:38
  • The developers of K2 have built a community for it as well. Have you tried to go directly to the source and ask for help? http://getk2.org/community – Paul Dessert Nov 15 '12 at 17:59
  • Have you tried anything yourself? – Lodder Nov 15 '12 at 21:05
  • I've updated my post with the code – WNR Design Dec 03 '12 at 22:42

1 Answers1

0

This solved my issue:

<div id="k2ModuleBox<?php echo $module->id; ?>" class="k2ArchivesBlock<?php if($params->get('moduleclass_sfx')) echo ' '.$params->get('moduleclass_sfx'); ?>">

  <?php
    foreach ($months as $month) {
        $years[$month->y][] = $month;
    }
  ?>
  <?php foreach ($years as $year => $months) : ?>
    <h4><?php echo $year; ?></h4>
    <ul>
        <?php foreach ($months as $month): ?>
        <li>
        <?php if ($params->get('archiveCategory', 0) > 0): ?>
        <a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&task=date&month='.$month->m.'&year='.$month->y.'&catid='.$params->get('archiveCategory')); ?>">
            <?php echo $month->name.' '.$month->y; ?>
            <?php if ($params->get('archiveItemsCounter')) echo '('.$month->numOfItems.')'; ?>
        </a>
        <?php else: ?>
        <a href="<?php echo JRoute::_('index.php?option=com_k2&view=itemlist&task=date&month='.$month->m.'&year='.$month->y); ?>">
            <?php echo $month->name.' '.$month->y; ?>
          <?php if ($params->get('archiveItemsCounter')) echo '('.$month->numOfItems.')'; ?>
          </a>
        <?php endif; ?>
        </li>
        <?php endforeach; ?>
    </ul>
    <?php endforeach; ?>
</div>
WNR Design
  • 105
  • 1
  • 2
  • 13