[wp-hackers] Hacking Assignment: Paging by Days
David House
dave at xmouse.ithium.net
Sun Sep 5 12:48:09 UTC 2004
Try this one out for size. It's not very optimised, rips a lot of code out from
ScriptyGoddess' plugin (so we'd need to check with her before making this core)
and I haven't tested it thoroughly, but anyway, here's my code:
http://xmouse.ithium.net/wp-content/code-snippets/other-stuff/page-by-days.phps
Quoting Ryan Boren <ryan at boren.nu>:
> 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
>
>
>
> _______________________________________________
> hackers mailing list
> hackers at wordpress.org
> http://wordpress.org/mailman/listinfo/hackers_wordpress.org
>
----------------------------------------------------------------
This message was sent using IMP, the Internet Messaging Program.
More information about the hackers
mailing list