博客存档列表问题

发布于 2024-11-18 09:00:03 字数 1425 浏览 2 评论 0 原文

在我的博客中,我的所有帖子均按日期 DESC 排序。我使用分页器,以便每个分页器页面包含大约 15 个帖子。我还有一个右侧栏,其中包含所有月份的链接列表我至少写了一篇文章:

ARCHIVES
 <a href="">january</a>
 <a href="">february</a>
 <a href="">march</a>
 [...]

我希望每个链接都指向分页器页面,该页面恰好是该特定月份的第一篇文章。如何动态地找到指向特定月份的 href 属性paginator-page?

我的基本页面是:

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..          
 }

我的帖子模型

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;      
 }
}

这是我用于检索每月列表存档的查询:

SELECT COUNT(*), YEAR(datetime) AS year, MONTHNAME(datetime) AS month FROM
posts GROUP BY year, month ORDER BY year, MONTH(datetime)

如果不清楚,请告诉

谢谢卢卡

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

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

掌心的温暖 2024-11-25 09:00:03

不知道我是否理解正确,但这应该很容易。

当您选择帖子时,查找该月的每个第一篇帖子并将其位置存储在数组中。
您现在知道要显示的帖子数量,并且知道每个页面有 15 个帖子,因此应该很容易找到您需要显示的页面。

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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文