Not about JavaScript

Posted by – November 15, 2008

In a context completely unrelated to “threaded” discussion comments on blog posts, Rob Pike once wrote:

Threads are like salt. I like salt, you like salt, we all like salt. But we eat more pasta than salt.

Implementing (what will eventually be) WordPress 2.7′s new threaded comments is not difficult, and doing so yields a moderately useful new organization element: threading, or individual replies, similar to the presentation of discussion forums, many newsreaders, the Gmail message list, or the Twitter @. This post by Ottodestruct has plenty of info to get you started against the latest subversion tip to get threaded comments working in your theme.

Many themes are built with, even around, JavaScript. If Simplish already loaded even one script, we’d certainly add the cool new threads. But Simplish is supposed to be simple, and it is supposed to be a feature that the theme loads no JavaScript in a default configuration.

I will probably link to a quick alpha Simplish with cut-and-paste test code for a threaded comments template shortly, but I’m interested in opinions right now.

11 Comments on Not about JavaScript

  1. demetris says:

    Josh, will the JS libraries still be loaded even if threading is not selected?

    btw, you can shave another five (5) bytes off your header PNG by running it through optipng: it went from 261 bytes to 256 bytes! :-o

  2. Otto says:

    If you want it to not load the javascript unless threading is turned on the the admin interface, use this code in the header.php:


    if ( get_option('thread_comments') && is_singular() ) wp_enqueue_script( 'comment-reply' );

    That will make it only load the comment javascript when threading is turned on AND you’re on the single post pages.

  3. josh says:

    @demetris: Patches accepted. Send me the .png! ;-)

    @Otto: Handy tip, and answers demetris’ question too. By default themes will load the comment script regardless of the wp-admin setting; but it’s easy enough to check for it with a conditional. Thanks for the comment!

    Like many things WordPress, I like this feature. I just like it better in a plugin — of which there were already several.

  4. josh says:

    @demetris: It’s in:


    Author: Demetris < > 2008-11-19 12:12:34
    Committer: Josh Wood <josh@impala.intranet.utopian.net> 2008-11-19 15:12:57
    Parent: 151ef711e85a5da02969a43cbb1bf6a3f1ff2159 (bumped to new RC version)
    Branch: master
    Follows: 2.1.2
    Precedes:

    add optimized background header image. Thanks Demetris @ op111.net.

  5. Otto says:

    I see your point with the plugin aspect, and normally I agree with you, but comment threading is something that really needed to be standardized. There were already too many ways of doing it, and for simple SEO purposes, it’s important for the methodology to be the same, or at least similar, amongst all sites. When the search engines can optimize to a particular layout, then their results become far more useful and more likely to drive traffic to your site.

    Also, the threading does work without javascript. It’s just not as nice and easy to use, requiring an extra and somewhat pointless page-load.

  6. josh says:

    @Otto: I decided when I typed the @Otto to the left that I was convinced. Let’s have comment threads!

    To wit, I’ll post a new post on this blog in a few minutes with my quick alpha-quality paste-together of threaded comments in Simplish. Your tutorial (linked above) was so helpful that you probably deserve an author line in the NOTICE file. :-)

  7. josh says:

    @Otto: Another note/a question: You wrote above:

    if ( get_option('thread_comments') && is_singular() ) wp_enqueue_script( 'comment-reply' );

    …where I think you meant is_single(). is_singular seems to be a variable. Do you know something I don’t, or was that a typo?

  8. [...] mentioned in comments on my original mild objection, I’ve been convinced that threaded discussions, new in the upcoming WordPress version 2.7, [...]

  9. Otto says:

    No, is_singular() was correct. It’s a function that returns the variable (much like all the other is_whatever() functions).

    is_singular() returns true on single posts, pages, and attachments. This is just slightly different from is_single().

  10. josh says:

    Aha! Thank you for the tip – important for doing stuff on other instances than a single post.