Articles by Month Joomla Module

Since I installed my site, I always was looking for a way to show my articles grouped by month. But Joomla only offers the "Archived Article" module, that only will show as its title says, your articles in archived stated.

It was incredible for me that Joomla didn't offer a way to filter the articles by month, even WordPress has a plugin for that included in the core. I just recently did a research and all the modules I found were commercial or they needed you to register, so I ask my self "let's try to hack the existing archived articles module ". The result was another module that I called " Articles by Month"

Download
a) Module installer mod_articles_monthly.zip
b) Component extra files monthly_component.zip


Install Instructions
The only problem for the moment is that I found that was not enough to modify the module: it is necessary to modify the view to add the filter to the resulting filtered articles. So I have to add extra files to the content component that you have to install manually.
I promise next time I will look for a way of how to install them from the module file.

1. Go to the extension manager menu and install the mod_articles_monthly.zip file.
This will add the module.

2. Manually open the monthly_component.zip file and extract the files.

3. Upload the file monthly.php to the directory /components/com_content/models of your Joomla site.

4. Upload the full directory monthly to the directory /components/com_content/views of your Joomla site.

Optional step
5. If you have an HTML override of the featured view in your Joomla template, go to the directory /templates/[your template]/html/com_content, make a copy the featured directory in the same directory and rename it to monthy.

One little issue
I realized that the module included articles like "About me" in the list. I didn't want this kind of content be shown as regular article. I had the idea of not show the "uncategorized" content, but I didn't like that so much. So I added the a secret filter: articles that have created or have a date previous to 1900, won't be shown. If you don't want to show an article, only modify its creation date like " 1899-01-01".

Enjoy.



For developers
This is how I hacked the archived content module:
First I thought that doing a copy of the archived articles and modifying the filter of the query will do the trick. I copied the full directory and I rename all the parts that said "archived" to "monthly" to have a new independent module. Then I looked in to the helper.php and changed this lines:

  
    // Original Filter: retrieve the archived content
    $query->where('state = 2 AND checked_out = 0');

    // New Filter: retrieve all the published content
    $query->where('state = 1 ');


Then I looked for the url who loaded the articles after click on the links of the module, this is what I found:
 $lists[$i]->link	= 
    JRoute::_('index.php?option=com_content&view=archive&year='
            .$created_year.'&month='.$created_month.$itemid); 

I changed the value of the parameter view to featured because I didn't want to show the ugly layout of archived articles. But that didn't work. So I checked the view featured in the views directory of the content component (/components/com_content/views) and compared it to the archived view. The featured view didn't implement the year and month filters.
I didn't want to modify the core component files that's why I copied the featured view and I created a new view called "monthly".

Then I checked out all the code in the files and I didn't find any traces of some query who show me the filters. I executed it anyway and I got a php error. After researching why that happened, I realized that I had to add a model file related to the view. I created the file monthly.php in the model directory and I could find the code that added the filter parameters:

// Changed this 
$this->setState('filter.published', 2);
//to
$this->setState('filter.published', true);

// Filter params
$this->setState('filter.month', JRequest::getInt('month'));
$this->setState('filter.year', JRequest::getInt('year'));

if ($month = $this->getState('filter.month')) {
   $query->where('MONTH('. $queryDate . ') = ' . $month);
}

if ($year = $this->getState('filter.year')) {
    $query->where('YEAR('. $queryDate . ') = ' . $year);
}

// Here I added the extra secret filter
$query->where(' YEAR(created) >= 1900 '); 


And that did the trick.


Only One annoying issue
When I tried to do the module installer, I always got a damn
JInstaller: :Install: File does not exist en-GB.mod_articles_monthly.ini
I got that because I had the following directory structure in my installer:

/languages
              |__ en-GB/en-GB.mod_articles_monthly.ini
              |__ en-GB/en-GB.mod_articles_monthly.sys.ini

I got rid off the extra "en-Gb" sub-directory and all worked fine.