duanliyi5997 2011-07-04 10:05
浏览 55

博客存档列表问题

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

  • 写回答

1条回答 默认 最新

  • dream5694 2011-07-05 10:34
    关注

    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.

    评论

报告相同问题?

悬赏问题

  • ¥20 关于URL获取的参数,无法执行二选一查询
  • ¥15 液位控制,当液位超过高限时常开触点59闭合,直到液位低于低限时,断开
  • ¥15 marlin编译错误,如何解决?
  • ¥15 有偿四位数,节约算法和扫描算法
  • ¥15 VUE项目怎么运行,系统打不开
  • ¥50 pointpillars等目标检测算法怎么融合注意力机制
  • ¥20 Vs code Mac系统 PHP Debug调试环境配置
  • ¥60 大一项目课,微信小程序
  • ¥15 求视频摘要youtube和ovp数据集
  • ¥15 在启动roslaunch时出现如下问题