Integrating tags into K2 - Trial by fire
ajax, k2, php, plugin, tagging, wordpress March 22nd, 2007I suppose you could call this the first actual post I’m making. Many of the things that have come before this were either automatically created by experimenting with Twitter Tools integration, or simply babble.
So this post is about tagging. I had already installed the Ultimate Tag Warrior plugin, because the K2 theme I’m using has built in support for it, but I just wasn’t feeling the love from it. So I took a chance and activated the Simple Tagging Plugin and a widget someone else had added to provide a cloud sidebar.
Which beings me to my first real experience adding a plugin to a theme that didn’t have builtin support. I had a little bit of exposure to the php already after working around a “404″ bug that WordPress 2.1.2 throws at you when you ajax. Long story short, if WP doesn’t think what you’re asking for is a valid page or permalink it’ll return html but it returns it with a “404″ status. Very wierd. It’s not a problem for Safari, but with IE and Firefox the XmlHttpRequest will punt the answer rather than hand it to the page’s jscript.
So how do you add the Simple Tagging Plugin? Turns out you hack it into the WordPress Loop. The loop is a file called “theloop.php” in your theme directory.
Wow.
Which appears to be how the entire very flexible, very powerful, blogging application works. All of the themes, all of the plugins, all of the widgets - they work together by cooperation and convention. Lots of people in the world are out there investing love and tears into this stuff. I’ll tell you what.
So here’s what I put in. I used my old favorite asp vbscript “inverted marker” technique where instead of escaping the code with <?php yadda(); ?> I’ll escape the html with the reversed tags like: ?><span class=”yadda”><?php
<?php
if (function_exists(’STP_PostTags’))
{
?><span class=”entry-tags”><?php
STP_PostTags();
?></span><?php
}
?>
See what I mean? Two reasons: I want to be able to read the code, and I want to chop all the accidental whitespace I can. This way the spans shouldn’t have any wierd linefeeds and stuff put out with them.
But it worked pretty well in the end. The plugin docs were pretty good and I guessed the correct place to shove it on the first try. K2 already had the UTW tags in there right where the simple tags needed to go, so that also had the example of what span class has the little tag on it.
Fun fun.
Recent Comments