Pagination - Index Blog Pages By Month

Permalink
BACKGROUND:
I'm trying to display an index page with a list of blog posts by from a single month. E.g:

Post 1 - 07 November
Snippet

Post 2 - 13 November
Snippet

etc.

Basicly what the page_list block does but filtered for a specific month. C5's date_nav block has the functionality for retrieving links and titles for individual blog entries. However, the format is in a dropdown ul.

QUESTION:
1. Any ideas on how to filter the page_list block for only specific month?

I'm intending to generate this page by the month the user clicks: i.e. User clicks on "November" -> Page with list of blog articles only for November.

Thanks in advance for any help!

 
cowland replied on at Permalink Reply
Seems that this will involve:

concrete/blocks/date_nav/view.php
and
concrete/blocks/page_list/templates/blog_index.php

And merging the functionality of the 2. Going to have a play.
Shotster replied on at Permalink Reply
Shotster
> Any ideas on how to filter the page_list block for only specific month?

Couldn't you use the filterByPublicDate() method? Or use whatever date you want to filter by. There's a magic method which allows you to use the camel cased version of an attribute handle after "filterBy". In other words, if you've created a page attribute with a handle of "blog_post_date" then you can filter on it by calling filterByBlogPostDate().

-Steve
jordanlev replied on at Permalink Reply 1 Attachment
jordanlev
I'm attaching a custom template for the autonav block I made a while ago. It lists pages by year/month, so it doesn't do exactly what you want, but hopefully the code will be useful to you.
cowland replied on at Permalink Reply
Jordan,

Thanks for the template - that's perfect for a sidebar navigation to individual pages.

I tweeked your file so it can display every single blog post: title, date, author, snippet, comments.

Seems to display entries in reverse order - (oldest first). Something I'll probably look at later.

Now to figure out how to pagenate different months on different pages!
cowland replied on at Permalink Reply
actually.. rather than making it complicated and pagenating the list of blog posts on different pages - a simple if statement could be used:

if ($pageMonth == $usermonth) {
   // echo blog entry
}


probably a lot more efficient than creating so many different pages!

- thou could use the "filterby" method steve was suggesting. would involve creating a pagelist - guess it would also help organise the list of entries!
cowland replied on at Permalink Reply
tried sorting the list by using pages:

Loader::model('page_list');
   $pl = new PageList();
   $pl->sortByPublicDateDescending();
   $pages = $pl->get();
   foreach($pages as $ni) {
      $_c = $ni->getCollectionObject();


Seems that the array $pages doesn't have the method getCollectionObject(). It returns me this message:

Fatal error: Call to undefined method Page::getCollectionObject() in concrete/blocks/autonav/templates/blog_monthly_archives.php on line 26

Any ideas how to initiate this method?
Or any work arounds?
cowland replied on at Permalink Reply
Alternatively can anyone sort existing entries by modifying concrete/blocks/autonav/controller.php to sort decending?

I recon around line 271 (function generatenav()) you need to put a value in related to the sorting around line 530.

I've tried putting various values in but it doesn't seem to change the chronological order of sorting.
jordanlev replied on at Permalink Reply
jordanlev
First of all, did you try changing the Autonav block options (in the edit dialog) to sort the list the way you want? I'm pretty sure there's a sort descending option available.

If not, though (or it doesn't do exactly what you need), you're going to have to change code in the controller, not the view -- the view only takes data that the controller has already queried and displays it, but if you want to alter the actual data queried then the controller is the place to do that.
I think you can override it by copying concrete/blocks/autonav/controller.php to blocks/autonav/controller.php -- that way you won't lose your changes when you upgrade the core system.

HTH!
cowland replied on at Permalink Reply
Cheers jordan, probably should've tried looking at the edit interface! sorted the list nicely.

I'm passing the month through the URL:

http://www.mydomain.com/blogmonths.php?cID=70&usermonth=Novembe...

And using:
$usermonth = $_GET['usermonth'];

For use in the if statement to sort the list.

Works beautifully =) - Just got to finalise implementation.

Not that it's relevant anymore but anyone got any ideas why "getCollectionObject()" for PageList class didn't work 3 posts back?
jordanlev replied on at Permalink Reply
jordanlev
Glad you got it working.

As for why your code 3 posts back doesn't work, I'm not sure off the top of my head but it looks like you combined code from the PageList model and the Navigation Helper (otherwise that "$ni" variable name doesn't make any sense). So in your code, the $ni IS the collection object already (I would rename it to $page or something more meaningful, but that's just a style thing). Calling ->getCollectionObject() I think is only applicable to using some method of the navigation helper class.

Or something like that...

-Jordan