new posts popup

September 15th, 2007

This is a feature I've wanted to have for a long time, but until now I didn't know how to realize it. I wanted to have some kind of a notification area for new events on the blog, so that a returning visitor could immediately see what has changed since the last visit. And I definitely didn't want it on the sidebar, it had to be above the fold.

So the concept was in the back of my head for months, but I couldn't figure out how to make it look good. Then I came up with the idea of making it a popup window. Not a browser window, of course, just a layer that would show if there had been new events. Otherwise it wouldn't show up. Yes, that sounds like something. So with some digging and research, a bit of hacking and lots of debugging, here is the final result.

new_posts_overlay_ss.png

The window conveys quite a lot of information. It lists the three posts last to be published (or commented on). This way you have new posts and new comments in the same place. In the screenshot, the top entry is a post made recently. The bottom two are older posts that have received new comments.

In terms of appearance, I wanted to make the window active only if the user is using it, so on page load it is made partially transparent, onMouseOver it becomes more opaque, and onMouseOut it becomes more transparent again.

For a demo.. you have this blog. After 15 minutes of inactivity your session will expire and the window will go away. To bring it back delete your cookies from this domain (or use a different browser) and it reappears. The session is handled entirely with cookies, so for visitors who don't accept cookies, the window will always appear as if this were their first visit.

Compatibility

The opacity property is new in CSS3 and isn't uniformly supported (yet). I've tested the plugin with the following browsers.

  • Firefox 1.0.1, 2.0.0.6
  • Opera 8.0, 9.23
  • Safari 3.0.3
  • IE 5.0, 6.0, 7.0
  • Konqueror 3.5.7 (opacity support is rumored to be on the way)
  • Netscape 6.0.1, 7.0, 8.0.2, 9.0b3

In addition, there's a rather pesky layout bug in IE <7.0 that causes the height of the window (which is floating above the other content) to be added to the top of the page. If you fix it, please send a patch. :)

Also, I tried very hard to make sure it only consumes one query, which unfortunately made it very complicated. If you rewrite it in simpler terms, send a patch. :)

Required MySQL version: 4.1+
How to use

Download, unzip, install, append the css to your styles. :cap:

UPDATE: Added Netscape.

UPDATE2: MySQL compatibility.

:: random entries in this category ::

17 Responses to "new posts popup"

  1. erik says:

    May I suggest different colour combinations? This one is almost illegible

  2. numerodix says:

    Is it? Well it's just css, hack it apart if you want. :D

  3. Manne says:

    This looks interesting, but would it be possible to base the last visit on latest login (I run a registered users only blog) rather than with a cookie?

  4. numerodix says:

    I'm sure it would, I haven't looked at the login system. But I don't see how that would change the behavior of this plugin, unless you're concerned about people who don't accept cookies (and the absolutely majority do).

  5. Manne says:

    If two people login from the same computer but with different users, they should be shown different posts/comments (I'm in a situation were this is the case...)

    BTW thanks for your fast reply!

  6. numerodix says:

    Yeah, that's a fact.

    Well it's yours, take the code and hack it apart. :)

  7. Manne says:

    well, I wish I knew how but unfortunately my knowledge of php is very limited..

  8. The Turkey says:

    I'm getting a MSQL syntax error ::

    WordPress database error: [You have an error in your SQL syntax. Check the manual that corresponds to your MySQL server version for the right syntax to use near '())-UNIX_TIMESTAMP(NOW()))) as post_date_unix, (UNIX_TIMESTAMP(]

    Any thoughts on a fix?

  9. numerodix says:

    Hm, something to do with the mysql version perhaps? What is yours?

  10. numerodix says:

    My host runs 4.1.21 and I've also tested with 5.0.44, they both work. 4.0.27 doesn't, because from what I gather there were some significant changes introduced in 4.1, including some of the functions I use in my query.

    At this point I'm not really itching to code for backwards compatibility, because I don't see myself going back to an earlier version. So I'm afraid you have to either upgrade or rewrite the query to not use UNIX_TIMESTAMP(). Mysql 4.1 was released in 2004, so it's probably safe enough. :)

  11. Omar says:

    Para que se escriba la cookie es necesario colocar el script al tope de la pagina y antes de escribir los encabezados.
    Si lo hago tengo errores en las capas.

  12. numerodix says:

    Omar:
    Yes, I know that is the way it is supposed to be done, but the plugin works the way it is on my site. If your site throws errors, then I imagine it might be conflicting with another plugin. But actually I don't quite know how to change this.

  13. [...] WP官方下载页面 | 插件作者下载页面 [...]

  14. joe says:

    I wanted to use this so I could get people to subscribe to my feed... can you do that?

  15. numerodix says:

    The popup and the feed have nothing to do with each other. Are you saying you want some kind of "subscribe to feed" button on the popup or something?