UPDATE/NOTE: This was coded against WordPress v2.3 so the line references may not be exactly the same in v2.5

Flickr doesn’t send over and category information when you blog to wordpress, so if you want to be able to blog from Flickr into another category other than your default one, try this hack.

It uses a tag you insert at the start of your Flickr blog html layout to set the category you want to post into. As you can have multiple blog templates, you can set a new one for each category you want to be able to blog to.

Look for the following piece of code in the xmlrpc.php file, it moves on different versions but it near line 550-560 and should be in the metaweblog.newPost method:

if (is_array($catnames)) {
    foreach ($catnames as $cat) {
        $post_category[] = get_cat_ID($cat);
    }
}

Insert this next bit just after the above:

if (strpos($post_content, "[") == 0) {
    $flickrcat = substr($post_content, 1, strpos($post_content, "]") - 1);
    $post_category[] = get_cat_ID($flickrcat);
    $post_content = substr($post_content, strlen($flickrcat) + 2);
}

In flickr, manually edit the blog template you are using so that it starts with [mycategory] where mycategory is your wordpress category you want to post to.You should have something like this:

[project365]
<div class="photoblog">
    <div class="photo">
        <a href="{photo_url}" title="photo sharing">
            <img src="{photo_src_m}" alt="{photo_title}" />
        </a>
    </div>
    <div class="text">{description}</div>
</div>

The category I want to blog to is ‘project365′. I have set the name of the blog in Flickr to benmarsh.co.uk : project365 so I know which category I’m posting to. It is quite easy to now extend this to allow you to post to another category by simply changing the [mycategory] tag.

3 Responses to “Flickr Wordpress category hack”

  1. Shawn | 08 March 2008 at 01:29

    Excellent! Just exactly what I was looking for! Thanks for the help!!

  2. Tim | 17 June 2008 at 15:29

    great hack– thanks!

    fairly obvious, but it might be noted that the category must already exist in wordpress or it won’t work. doh.

  3. Ben | 17 June 2008 at 20:32

    Cheers Tim, I have an updated plugin version of this now which I use on this site, it just needs a few tweaks before I publish a copy of it. It’s worth noting that this code is from WordPress v2.2/v2.3 so those exact code blocks might not be there any more.

Leave a Reply