Keyword

[SOLVED] K2 Tools archive module sort by year than month

  • Wouter
  • Wouter's Avatar Topic Author
  • Offline
  • New Member
More
11 years 10 months ago - 11 years 10 months ago #107100 by Wouter
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

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

Please Log in or Create an account to join the conversation.

  • Wouter
  • Wouter's Avatar Topic Author
  • Offline
  • New Member
More
11 years 10 months ago #107101 by Wouter
anyone?

Please Log in or Create an account to join the conversation.

  • Wouter
  • Wouter's Avatar Topic Author
  • Offline
  • New Member
More
11 years 10 months ago - 11 years 10 months ago #107102 by Wouter
<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;

    }
}

Please Log in or Create an account to join the conversation.

More
11 years 7 months ago #107103 by artyom
Good day. I have this problem too. You already have the solution?

Please Log in or Create an account to join the conversation.

More
11 years 7 months ago #107104 by Axel
I'm wondering about this as well. Best of all would be some sort of accordion like style

so

2013
-jan
-feb
...

2012
-jan
-feb
...

etc. But the months only show when you press the year. I have an archive showing jan-dec for 2010 - 2013 now, thats a very long list :D

Is there a plugin/module to achieve this or can it be done by simply changing the archive.php some easy way?

Please Log in or Create an account to join the conversation.

More
11 years 7 months ago - 11 years 7 months ago #107105 by Axel
SOLVED (at least for my needs)

Here is a working example of the nested months under years (on the right side under title "ARKIV")

So this is what I came up with as a working solution on this subject (for my current needs).

Thanks to the answer on stackoverflow combined with JQuerry accordion widget I was able to put together the following code

archive.php – Copy (don't move) this file from
SITEROOT/modules/mod_k2_tools/tmpl/
to
SITEROOT/templates/YOURTEMPLATE/html/mod_k2_tools/)

for sake of ease, select all and paste the following
	GANTRY
 with 
	LESS CSS
 and 
	FontAwesome
 here, so if your using another base, you'll need to modify the CSS a bit  ;)

I would also suggest using the minified version of the JQuerry UI for this. You can download the same settings I used here or just reset and chose the ones you want.

PS. Don't forget to change "YOURTEMPLATE" to your actual template name ;) DS

Please Log in or Create an account to join the conversation.

More
11 years 7 months ago #107106 by Axel
If anybody feels like helping out on the next step to this, it would be much appreciated :)

What I would like to achieve now is the following structure

-YEAR 1
-- month 1
--- post 1
--- post 2
--- post 3

-- month 2
--- post 1
--- post 2
--- post 3

-YEAR 2
-- month 1
--- post 1
--- post 2
--- post 3

-- month 2
--- post 1
--- post 2
--- post 3

etc.

So, basically what I have, just adding another list of items posted (with the title of the item) under each month :)

Like I said, any help on this is greatly appreciated. I will post the final code here (unless *crossing fingers* someone else beats me to it :woohoo:)

Please Log in or Create an account to join the conversation.

More
11 years 2 months ago #107107 by Balgas
Hi !
I've installed your method for archives but it seems to have a conflict of jquery on my page...
My galery doesn't work :(
the ink : www.mycreaweb.fr/zakhor/manifestations.html

I use joomla 2.5.11 & K2 2.6.7

Thx for your help

Please Log in or Create an account to join the conversation.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 2 months ago #107108 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 Tools archive module sort by year than month
Hello to all,

If you are experiencing JS Conflicts you should try the methods described here api.jquery.com/jQuery.noConflict .

JoomlaWorks Support Team
---
Please search the forum before posting a new topic :)

Please Log in or Create an account to join the conversation.

More
11 years 2 months ago #107109 by Balgas
When i disable this line my galery works : <script src="//ajax.googleapis.com/ajax/libs/jquery/1.9.1/jquery.min.js"></script> nut my accordeon effect on archive not.

How can i have no conflict beetween jquery ? I test your link, but i can't find the solution...

Please Log in or Create an account to join the conversation.


Powered by Kunena Forum