Comment on paragraphs – WordPress Plugin

Last week I posted about a little wordpress plugin I wrote called FancyCatlist. It made a nice little category menu similar to the kind of thing you would see on Everyblock. I wrote it as part of the process of putting together one of the sites I want my students to use next year as part of their practice in online publishing. You can see it in action on the ‘work in progress’ site.

The site is a ‘beatblog’ kind of thing and in searching around for examples of different approaches to this kind of thing I stumbled back upon ‘community news engine’ Newsmixer.

Newsmixer.com
Newsmixer.com

Its a nice idea and especially impressive as it was a jschool project which you can find out more about on the site itself. But the bit that caught my eye was the ability to comment on each paragraph of the content (and more as you’ll see if you go and explore)

I liked that idea as it taps in to the ‘One Par. One fact’ discipline of  basic journo writing and turns it in to a kind of microlink activitiy. It also begins to stem ideas off from various parts of an article, not just an article itself. Of course the reverse is that it could abstract all meaning out of the text. But used well, as I think it is here, I think it stands up.

So I think to myself that this would be a nice feature to have on the students publication website. But not, in the first instance,  as a way of the reader leaving feedback but as a way for me to leave feedback. A way that I could comment on each paragraph to give students feedback on what they write. I should point out that as I write this, it’s the policy of the department to keep student publications behind a firewall (I’m not so happy with that but hey ho). So feedback in the open is not a problem.

Finding a micro-comment plugin

I had a look around to see what was out there that would do a similar thing. This included poking around the newsmixer source (which is opensource) to see if it was worth using their framework. But they are using python. Great but my head (and life) is too crammed to learn that. Ryan Mark, one of the developers of newsmixer, has announced that newsmixer is heading the way of an API and there will be a wordpress plugin to tap in to all the neat features. But that seems a way off.

The next thing I did was search for wordpress plugins.  The closest I found was marginalia which looks very nice but doesn’t seem to play well with WordPress 2.8 and even with some nice features didnt look like it would scale back to what I wanted.

So I wrote another plugin.

The Feedback By Paragraph plugin

Feedback by Paragraph is a plugin that does a number of things

  • It hijacks the content of the post, looking for the </p> tag and inserts some code that attaches a pop-up box to that paragraph so you can leave comments. It inserts a little bubble with a link to open the box which also displays the number of comments there already. It only does this on the article page (what WP calls a single post as defined by the template single.php). It uses the closing p tag because it’s the easiest one to find as the <p> is often full of crap like classes etc and my regex is not really up to that. Using </p> also has the advantage of picking up any image captions without breaking the styling class.
  • It saves any paragraph comments with a custom ‘comment type’ so that they can be associated with a paragraph
  • It filters out any paragraph comments from the normal comment display.
  • It only allows you to comment if you are an admin or the post author but anyone can see the comments.
Feedback By Paragraph
Feedback By Paragraph

You can see it in action  the beatblog site

An issue.

This is now resolved.

There is a big issue to be aware of with this plugin.  When you submit a comment form with a custom comment_type defined  it isnt processed like all the other form elements. I’m not sure why that is but it takes an ammendement to the one of the core files in wordpress to make it (at least that’s the only way I got it to work). That means a tweak to a file called wp-comments-post.php.

Around line 40 you need to add the line

$comment_type = ( isset($_POST['comment_type']) ) ? trim($_POST['comment_type']) : null;

And around line 62 you need to change

$comment_type = '';

to

//$comment_type = '';

I know, not ideal. I’m sure there is a better way to do this which involves hooks and filters and all that. Please if anyone has even half an idea how this might be done I’d love to hear. But I have yet to find it(or understand it).

How do I use it?

You can download the plugin to try.

What next

There is plenty of flexibility in this plugin and an options page wouldn’t go a miss. I’ll be looking at setting it up so that you have more control over who sees what and perhaps look at setting a template for the comments form so that it isnt hidden in the plugin code. But for now, given that my sites are behind a fire wall it seems to work for me.

Let me know if you download and try the thing. Oh, and don’t forget that tweak of the core file.

NOTE: First bug fix! This version makes the call to the database for the comments using the generic form rather than being hard coded to a particular table. Sorry!

Visit the feedbackBP plugin page

Enhanced by Zemanta

14 thoughts on “Comment on paragraphs – WordPress Plugin”

  1. Thanks for the comment Nick

    The restriction is based purely on the way I’m going to use it as a student feedback mechanism. By restricting commenting to admin (me) and the post author (the student) I can control the dialogue but the other students can see the comments – share the knowledge.

    It means the restriction, based on user level and author ID, is placed against the actual comment function rather than the whole plugin. Not a big deal to change and maybe best done with an options page in a later iteration.

  2. I too was frustrated by Marginalia and CommentPress (both are derivations of each other). The user interface was confusing.

    Yours is more straightforward!

    Several observations / suggestions:

    1. The comment box is wider than the width of the popup window. I am using Safari 4.x on Windows.

    2. For paragraphs that have comments attached, the qty-indicator should be a different color than the ones that have zero comments. That will help a quick scan to easily spot the paragraphs that need attention.

    3. When clicking on a comment-qty-indicator that has a non-zero value, could the comments be shown directly below the paragraph? The popup “gets in the way”. This way, when printing the page to hard-copy or to PDF, all the relevant comments will have been “captured”. Its also easier to scan down and see it all in context.

    Thanks again, and let me know if you need coding help ! (you’ve got my correct email address via this comment form)

    :-)

    1. MacBoy. Thanks for the comments. Really useful.

      1. I just need to make an adjustment to the styles sheet to sort this. I put a lot of reset stuff in there trying to sort out an earlier problem
      2. I tried to keep the comment indicator as low-key as possible so that it didn’t distract from text. I think a quick change to the code that amended the link with a style call would sort that.
      3. The comments are all held in an ‘invisible’ div so there would be no reason why a ‘print style sheet’ couldn’t be put together to make a decent print of the page.

      Work is taking the priority at the moment so development on anything too fancy will take a while but there are some good ideas for tweaks there.

  3. Hi, is it possible to limit the comments to only be seen by admins of the wordpress site? This way it could be used in to collaborate on WordPress blog posts (if there are for instance many freelancers collaborating on a post).

Leave a Reply