In my blog I have all of my posts sorted by date DESC.I use a paginator so that every paginator-page contains about 15 posts.I have also a right-side column where I have a link-list for all of the months that I wrote a at least a post:
ARCHIVES
<a href="">january</a>
<a href="">february</a>
<a href="">march</a>
[...]
I would like that each of these links points to the paginator-page where happens to be the first post for that specific month.How can I find dinamically the href attribute pointing to the specific month paginator-page?
My basic page would be:
class IndexController extends Zend_Controller_Action
{
public function indexAction()
{
$postmgr=new Post();
$currentpage=1;
$page=$this->_request->getParam('page');
if(!empty($page))
{
$currentpage=$this->_request->getParam('page');
}
$paginator=$postmgr->paginatePosts($currentpage);
$this->view->paginator=$paginator;
//then I build my monthly archive list..
}
And my post Model
class Post extends Zend_Db_Table_Abstract
{
function paginatePosts($page=1)
{
$q=$this->select();
$q->order('datetime DESC');
$paginator=new Zend_Paginator(new Zend_Paginator_Adapter_DbTableSelect($q));
$paginator->setItemCountPerPage(15);
$paginator->setCurrentPageNumber($page);
return $paginator;
}
}
This is the query I use for retrieving the monthly list-archive:
SELECT COUNT(*), YEAR(datetime) AS year, MONTHNAME(datetime) AS month FROM
posts GROUP BY year, month ORDER BY year, MONTH(datetime)
Let me know if it's not clear
Thanks
Luca