Infinite Scroll for Wordprss

Wordprss is coming along nicely as I commute back and forth from work. Here’s what’s done, and some fun issues with how to implement the next big feature: infinite scrolling (like twitter, facebook, etc. all do).

What’s done:
When you start up, there are a couple of pre-subscribed feeds.
They have entries.
As you use it, they will begin to update themselves to show new stuff posted on the internet.
If you like, you can add other feeds in.
Putting in a website, wprss will do it’s best to find feeds there to subscribe to and will let you choose among them.
You can remove sites you are no longer interested in.
As you read things, they mark as read and won’t show up unless you go looking for them. You can always unmark them so they will show up next time you come back to that feed.

So now you have most of a working feed reader. Any time you select a feed, I pull in the last thirty items for that feed. Once you reach the end of those thirty things, it would be good if we just showed you more entries rather than making you click “more” or refresh the feed link. This is usually called infinite scrolling and it is solved for most websites. The way this plugin is structured presents some issues though.

Building this feed reader as a plugin in WP has saved TONS of time in some ways. No need to build a routing system, DB configuration, or user management – all done thanks to WordPress. Instead there are slightly different challenges: the backend api isn’t very RESTy because that’s not how AJAX works in wordpress. Queueing up javascript libraries involves arcane calls and registrations.

And there isn’t really a way to do pagination in this setting. The classic inifinite scrolling solution is by Paul Irish, and is based on this well argued inifinite scroll implementation by Alex Micek. But they rely on infinite scrolling as a graceful upgrade to pagination. We don’t need that because this isn’t a part of your site that will ever see a search engine. Instead we have a list that is mutable, which is it’s own special challenge. See in the classic solutions, you are looking for a way to append “Page 2” of your essentially static site by the time you reach the bottom of “Page 1”. Instead, we have a list of entries – and you just want to get the next 30 or so unread entries.

So here’s the idea I’m going to try. There will be only one php backend method that gets you the next 30 unread entries. At the bottom of the list of feed entris there will be a cute display letting you know we are about trying to load more. So if you just quickly scroll all the way to the bottom you’ll see something like this:

Hey, wordprss is fetching more entries for you. They’ll show up here in just a jiff.

Every time you get close to the end of the page, we’ll call that method and get the next 30 unread entries. Then we append those on and you’ll see the new entries ready to read. Get close to the end and you’ll see that loading message again – or maybe we’ve already fetched more for you in the meantime.
Eventually you’ll reach a point where you’ve gotten all of the feeds. I think if the get_feeds function returns less than 30 feeds we can put in a different helpful messsage:

OH NO! You’ve read everything here in this feed. Try “h” or “l” to go to a feed with unread items – or maybe this is a good time to put in a thank-you donation to the EFF or SFLC.

This unfortunately means I can’t just use the stuff that is already out there and working. I’ll have to actually read it and understand it. And write my own. Which is what every geek really wants to do all along.

But wait, there's more

Leave a Reply

Your email address will not be published. Required fields are marked *