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.

    评论

报告相同问题?

悬赏问题

  • ¥15 为什么使用javacv转封装rtsp为rtmp时出现如下问题:[h264 @ 000000004faf7500]no frame?
  • ¥15 乘性高斯噪声在深度学习网络中的应用
  • ¥15 运筹学排序问题中的在线排序
  • ¥15 关于docker部署flink集成hadoop的yarn,请教个问题 flink启动yarn-session.sh连不上hadoop,这个整了好几天一直不行,求帮忙看一下怎么解决
  • ¥30 求一段fortran代码用IVF编译运行的结果
  • ¥15 深度学习根据CNN网络模型,搭建BP模型并训练MNIST数据集
  • ¥15 C++ 头文件/宏冲突问题解决
  • ¥15 用comsol模拟大气湍流通过底部加热(温度不同)的腔体
  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛