Keyword

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

  • Wouter
  • Wouter's Avatar Topic Author
  • Offline
  • New Member
More
12 years 6 months ago - 12 years 6 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
12 years 6 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
12 years 6 months ago - 12 years 6 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
12 years 3 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
12 years 3 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
12 years 3 months ago - 12 years 3 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
12 years 3 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 10 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 10 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 .

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

More
11 years 10 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.

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 10 months ago #107110 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 Tools archive module sort by year than month
You have to make sure that these script are compatible with jQuery 1.9.
You can always choose 1.8 or 1.7 through K2's parameters.

As for the nocoflict you can use the Example: Create a different alias instead of jQuery to use in the rest of the script.
var j = jQuery.noConflict();
 j(function() {
                j( "#k2-archive-heading" ).accordion({ heightStyle: "content" });
                });

Also you are loading the script from your localhost, you must change the source to it's correct location.

Finally loading scripts should be done with the Joomla! API. More on this can be found here docs.joomla.org/JDocument/addScript

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

More
11 years 10 months ago #107111 by Balgas
NICE !!
I delete the script : <script src="//ajax.googleapis.com/ajax/libs/jquery/1.6.3/jquery.min.js"></script>
& load on K2 jquery v.1.9.0 & it's work !
Thx a lot !!!

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

  • Krikor Boghossian
  • Krikor Boghossian's Avatar
  • Offline
  • Platinum Member
More
11 years 10 months ago #107112 by Krikor Boghossian
Replied by Krikor Boghossian on topic Re: K2 Tools archive module sort by year than month
You 're welcome

Also you are loading the script from your localhost, you must change the source to it's correct location.


Make sure you 've corrected that too because it will crash in all other users.

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

More
11 years 10 months ago #107113 by Balgas
Oups ! Thx a lot ^^

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

More
11 years 10 months ago #107114 by Federico Falciani
Replied by Federico Falciani on topic Re: [SOLVED] K2 Tools archive module sort by year than month
Thank you for the posted solution: it works, but I have a problem: it shows just the last 3 years archived, and I need it shows all the years archived.

Waiting for your response.

Thank you very much.

Federico.

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

More
11 years 10 months ago #107115 by Paul76
We're having the same problem, e.g. using K2 Tools without any modifications, date navigation elements for stories older than 3 years aren't appearing. So where we have a post from November 2010, the list stops at April 2011. Any suggestions?

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

More
11 years 9 months ago #107116 by Alaa
Hello,

Thank you indeed for your input. Please the solution didn't work on my site. The year appears but with no style and no animation! I think the JQuery didn't work. Do I have to do something to import the JQuiry animation? Can anyone just upload the file of JQuery that I should use?

Please help me. I really like this and need it.

I don't know anything about JS and JQuery.

Thank you advance.

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

More
11 years 7 months ago #107117 by Nicholas Loggie
Replied by Nicholas Loggie on topic Re: K2 Tools archive module sort by year than month
Great contribution - thanks very much

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

More
11 years 6 months ago #107118 by raffaEl
Dears!!

This is wonderfull solution!

I've got two questions, how can we improve this:

1. When clicking on monts from earlier yeras (ex. 2012) tabs get back to 2013, the same when we're inside the article. How can I modify the code to maintain year selected from archive?

2. Can we extend this to show articles list below selected month? That would be perfect, exectly like Blogger archive works!

Best Regerds,
raffaEl

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

More
11 years 6 months ago #107119 by Bruno Ferreira
Replied by Bruno Ferreira on topic Re: K2 Tools archive module sort by year than month
Please post your code modifications.

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


Powered by Kunena Forum