开发者

Blog Archive-list issue

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


Dont know if i understand you correctly but it should be pretty easy.

When you select your posts find every first post of the month and store its position in the array. You now know the number of the post you want to show and you know every page has 15 posts so it should be easy to find out on which page you need to be.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜