Check out my latest project: Full Frontal JavaScript Conference

TextMate Tagging with Simple Tagging

I recently upgraded to WordPress 2.2 and found that Ultimate Tag Warrior wasn't working anymore for me. Although I managed to hack it a bit and eventually found UTW 3, the biggest problem (and show stopper) was when a new comment was placed on a post, all the tags would disappear.

So I've moved to Simple Tagging which imports UTW tags and works just fine.

Now for the patch to allow me to tag from textmate.

Blogging Bundle

As per my tutorials on how to support tagging from TextMate for Ultimate Tag Warrior you have to patch the blogging bundle. You can use my patch, or patch the blogging.rb file yourself.

Note: that if you've done this before (from a previous tutorial), you don't this to do this again and you can skip to the XMLRPC changes.

Automatically Patching Blogging Bundle

Download the latest blogging.rb patch and run the patch command:

patch -p0 < blogging.rb.patch

Manually Patching Blogging Bundle

You'll need to edit the blogging.rb file in the /Applications/TextMate.app/Contents/SharedSupport/Bundles/Blogging.tmbundle/Support/lib/ directory.

Find the following lines:

@post['mt_tags'] = @headers['tags'] if @headers['tags']

Then copy it below the

elsif self.mode == 'wp'

Then change:

@post['mt_allow_comments'] = @headers['comments'] =~ /\b(on|1|y(es)?)\b/i ? 'open' : 'closed' if @headers['comments']
@post['mt_allow_pings'] = @headers['pings'] =~ /\b(on|1|y(es)?)\b/i ? 'open' : 'closed' if @headers['pings']

And change the instance of 'open' to '1' (keeping the number in the quotation) and 'closed' to '0' (again keeping the quotation), so you have this:

@post['mt_allow_comments'] = @headers['comments'] =~ /\b(on|1|y(es)?)\b/i ? '1' : '0' if @headers['comments']
@post['mt_allow_pings'] = @headers['pings'] =~ /\b(on|1|y(es)?)\b/i ? '1' : '0' if @headers['pings']

The second lot of changes (comments and pings) are added because WordPress 2.2 changes the flag it requires to turn these features on.

XMLRPC Changes

Next we need to change the xmlrpc.php file that should be located in the root directory of your blog. I am providing my own copy of xmlrpc.php for download, but please be warned that I am using WordPress 2.2 and I have no idea whether this specific file will work with previous versions.

Either way: backup your files!

Download xmlrpc.php for WordPress 2.2

I do know, however, that manually patched (using the instructions below) the tagging should work regardless of the WordPress version.

Manually Modifying xmlrpc.php

Step 1 - modify the setters

In the functions mw_newPost and mw_editPost add the following line of code:

$_REQUEST['tag_list'] = $content_struct['mt_tags'];

Above the comment in each of those functions, that reads:

// We've got all the data -- post it:

Step 2 - modify the getters

In the functions mw_getRecentPosts and mw_getPost, find where the array is built ($struct[] = array and $resp = array respectively) and add the following as the first array item:

'mt_tags' => get_keywords($post_ID),

Step 3 - get tags from Simply Tagging

Add the following function in the xmlrpc.php file (I've added it to the end of the file - but it doesn't matter, so long as it's global):

function get_keywords($postid) {
  global $STagging;
  $STagging->_postids = $postid;
  $tags = $STagging->getPostTags($postid, true);
  return (implode(', ', $tags));
}

Finishing up

That's everything you should need to be able to enable tagging from TextMate to Wordpress using Simply Tagging.

Keep reading for a few other tips, and let me know how you find this tutorial.

A Fix for Tag URLs

I noticed that my particular install of WordPress 2.2 and Simply Tagging 1.6.8 didn't handle /tag/textmate properly. It kept saying 404 not found.

I wrote a fix and patched my version of Simply Tagging to get it to work. Edit simpletagging.php and change line 697 from:

$this->search_tag = stripslashes(get_query_var($this->option['query_varname']));

To:

$this->search_tag = preg_replace('/\//', '', (get_query_var($this->option['query_varname'])));

And Finally: Ecto Tagging

Though I don't use Ecto, I'm pretty certain if you follow the instructions in the xmlrpc section, and follow the first two steps from Robin Lu's - How to make Ecto work it should enabling tagging.

7 Responses to “TextMate Tagging with Simple Tagging”

  1. I have a small problem with simpletagging plugin.

    When i go to individual "tag pages", the blog posts are displayed in full. i dont want to show full posts on those pages. i just want to show two-three lines of each article. how do i do it?

    plz help.

  2. @Vinit - I'm not quite sure. I tend to use the comment in WordPress which only previews the part above the cut.

    Alternatively you could edit the simple tagging code to only print the first line or two...?

  3. Hello, I have a problem with simple tagging.
    How to show only categories in "filed under..." but no tags? (just like your blog)
    It really bugs me.
    Thanks

  4. @Ken - having a quick look at your blog (lajag.com) it's just the template that says 'filled under...'.

    I happen to show both categories and tags. It should be just a simple change to the template that you're using.

  5. Maybe you can help me as well... I have simple tagging installed on wp2.2.2 some of my tags work.. and others do not. e.g. the tag "marketing" results in a 404, however if you look in the "most popular posts" section, and select one of the posts, you will see it obviously has the tag marketing. Some of the tags work.. like "food" or "Direct Sales" for example, but it only lists a few of the posts and the full posts at that.

    The most popular widget (widgetized and modified from AKPC) automatically filters posts by the tag, so you can get an idea of the problem by simply selecting some of the tags, and then viewing the posts shown in most popular.

    FYI, it was working, but then I went to the "Mass Edit" page, and was cleaning things up a bit (fixing caps, deleting crap)

    Anything you can do to help would be much appreciated.

  6. @vinit

    I found a simple and quick way to display only the excerpts. Make a copy of your search.php theme file (this is used to display search results) and name that copy tags.php Now when someone clicks on a tag, it displays the same way as your search results.

  7. so it fixed itself... (here's what i did just in case)

    I created a template called tags.php (by copying search.php) and edited it to display the tag being selected.

    I changed line 587 as you note for line 697 (I'm assuming this is due to some of the changes you were making above)

    I did a permalink update

    I created a file that changes the number of results per page depending on query type (month, day, category, etc..)

    And somehow viola !! it's working. Hopefully I'm not wrong http://grapethinking.com