Date Navigation Block with Page Counter

Permalink
I've been trying to figure out a way to display the number of pages that my website's blog has within the date navigation block. The view.php page is very simple. So simple, in fact, that I cannot seem to find a relationship between the date controller and nav controller.

Basically, I would like the output to look like this:

September 2015 (6)
October 2015 (13)
November 2015 (8)

Any ideas? I have googled this like crazy and found nothing even close.

 
jordif replied on at Permalink Best Answer Reply
jordif
Hi!

First, I'm not an expert on this block, so maybe someone has a better solution.

All the logic is in the controller.php file, that's where the Date Navigation block gets and filters the page list.

So I think you should override the controller block or create a new block based on the core Date Navigation block.

Then in the controller you should change this line:

$query->select('date_format(cv.cvDatePublic, "%Y") as navYear, date_format(cv.cvDatePublic, "%m") as navMonth');


to:

$query->select('date_format(cv.cvDatePublic, "%Y") as navYear, date_format(cv.cvDatePublic, "%m") as navMonth, COUNT(cv.cID) AS counter');


This should get the number of pages.

Also in the controller change this line:

$dates[] = array('year' => $row['navYear'], 'month' => $row['navMonth']);


to:

$dates[] = array('year' => $row['navYear'], 'month' => $row['navMonth'], 'counter' => $row['counter']);



This should make the counter variable available in the view.php file, so you could print it like this (within the $dates loop):

<?php echo $date['counter']; ?>



Hope this helps!

Jordi
andrewloehr replied on at Permalink Reply
You are awesome. I made a template for the block in the application folder with the changes that you made and it worked FLAWLESSLY! Thank you SO much. I would have spent forever trying to figure this one out!
jordif replied on at Permalink Reply
jordif
Glad it helped :)
oximasarl replied on at Permalink Reply
Hello,

I'm looking a way to filtered only by years and have something like this :
2020 (8)
2019 (12)
2018 (6)

If it's possible to modify the navigation date block or in other case use a add-ons.
Thanks.