[wp-hackers] Hacking Assignment: Paging by Days

Ryan Boren ryan at boren.nu
Sat Sep 4 19:35:23 UTC 2004


As I mentioned in reply to Podz' mail, the code for paging by days is
very simple-minded.  It divides the query up into blocks of days.
However many posts there are in that block, if any, are displayed.  What
most people expect to happen when they ask that posts be paged by 5 days
is that 5 "days worth" of posts be displayed.  This is a more
complicated query.  Actually, it can be multiple queries.  Anyone want
to take this on?  You might be able to make use of ScriptyGoddess'
Next/Previous Archive Date code for finding the next day that has a
post.

http://www.scriptygoddess.com/archives/2004/06/27/previous-archive-date-
next-archive-date-links/

You'll need the latest CVS.  Look in get_posts() in classes.php.  Here's
what the current paging code looks like.

	} else if (empty($q['nopaging']) && ! is_single()) {
	  $page = $q['paged'];
	  if (empty($page)) {
	    $page = 1;
	  }

	  if (($q['what_to_show'] == 'posts')) {
	    $pgstrt = '';
	    $pgstrt = (intval($page) -1) * $q['posts_per_page'] . ', ';
	    $limits = 'LIMIT '.$pgstrt.$q['posts_per_page'];
	  } elseif ($q['what_to_show'] == 'days') {
	    $lastpostdate = get_lastpostdate();
	    $lastpostdate = mysql2date('Y-m-d 00:00:00',$lastpostdate);
	    $lastpostdate = mysql2date('U',$lastpostdate);
	    $startdate = date('Y-m-d H:i:s', ($lastpostdate - ((intval($page)
-1) * ($q['posts_per_page']-1) * 86400)));
	    $enddate = date('Y-m-d H:i:s', ($lastpostdate - (intval($page) *
($q['posts_per_page']-1) * 86400)));
	    if ($page > 1) {
	      $where .= " AND post_date > '$enddate' AND post_date <
'$startdate'";
	    } else {
	      $where .= " AND post_date > '$enddate'";
	    }
	  }


You'll need to smarten the code for the what_to_show == days case.

Ryan

Here's the problem as described by Podz:

On Sat, 2004-09-04 at 13:48 -0500, Ryan Boren wrote:
> On Sat, 2004-09-04 at 19:37 +0100, Podz wrote:
> > Upgraded to the latest build earlier.
> > 
> > 1. Category views broken.
> > - Would not show posts in cats that I knew existed.
> > - Would show 1 post in another cat, I click Next Page, it says 'Sorry no 
> > posts..', I click Next Page again, and I see another post
> 
> You're paging by days, yes?  The paging code for days has always been
> rather dumb.  It pages by blocks of days.  If there are no posts in that
> block, no posts are shown.  If we don't get this fixed, we'll probably
> just turn off paging everywhere except the home page when paging by
> days.
> 
> > 2. Pagination. Unclear where to change the number of posts displayed.
> > 
> > 3. Archives view broken. With 1.2 or 1.3 rewrite rules, it showed no 
> > posts for April and May.
> > 
> > 4. Plugins: Sortable archives, DelyMyth's stats, Stats (by Ryan 
> > Callaghan) all break.
> 
> I believe some rely on "posts paged", which is now gone.
> 
> Ryan





More information about the hackers mailing list