The Quick & Dirty:

  • 9+ years in the biz, 10 messing around
  • All the latest in HTML, CSS, JS & PHP (Sorry, no .net or Ruby skills yet)
  • Cross-browser compatible code from Photoshop or Illustrator files.. or napkins!
  • Custom Specialities in Wordpress theming & plugins, Twitter & jQuery
  • Subversion, server-log analysis, and blocking hack-attempts (of late).
  • Data/Project Geek. I ♥ timelines.

I’ve compiled some handy PHP functions I’ve had to whip up. More extensive code-samples are also available.

Wordpress-from-Photoshop/Illustrator

Wordpress-from-static HTML

Wordpress-from-Photoshop

Auto WordPressing!

So I’ve been trying out a new system of blogging for me. It’s not enough that I can write my thoughts down here within WordPress’ editor, I find myself wanting to promote those other articles and blog-items from other sources. Since I read them on Google Reader, and since that system is kind enough to provide an RSS feed of all that I like or “Share”, why not import that into¬† this blog? So I solved that bit with FeedWordpress. There’s also WP-o-matic, which seems to be a bit less stable for me (but that might be my config) but it does local image cacheing.

Which brings me to my second point: if I’m pulling in all these posts, what happens when the source-image disappears? For that I found 2 more plugins: Hot Linked Image Cacher, which despite doing the job, doesn’t import into WP’s Media Library like Matt Mullenweg’s Cache Images. The latter does seem to need confirmation every once-and-awhile; I think it might even be duplicating some images :(

Finally, now that I have all of these posts being added, I want to both auto-tag AND auto-categorize ‘em. There’s a million auto-taggers (I’m using Web Ninja Auto Tagger for now), but there’s not a single auto-categorizer!

So I made the world’s dumbest auto-categorizer: it uses the title, excerpt & content, and sees if there’s any matching words/phrases the same as the category name. Pretty bad, huh? But it works well enough for me:

[sourcecode lang="php"]
/* Auto- categorize posts! */
add_action( ‘edit_post’, ‘auto_cat’ );
function auto_cat( $post_id ) {
global $post;
//get the content, excerpt & title, put ‘em together
$copy=$post->post_title.” “.$post->post_excerpt.” “.$post->post_content;
//get all the categories
$categories=get_categories( array(‘orderby’ => ‘name’, ‘order’ => ‘ASC’) );
//see which ones overlap
$addcat=array();
foreach($categories as $category) {
if(stripos($copy,” “.$category->name.” “) !== false){
$addcat[]=$category->cat_ID;
}
}
// add new & old cats category
$categories = wp_get_post_categories( $post_id , array(‘fields’ => ‘ids’)); //returns cat_IDs
$categories = array_merge( $categories, $addcat );
//filter out dup’s:
$categories = array_unique($categories);
if(count($categories)>1) {
//remove “uncategorized”
$tmp=array_flip($categories);
$uncat_id=$tmp[1]; //should also be 0 or 1 oddly enough!
unset($categories[$uncat_id]);
}
//set the new category list
$a=wp_set_post_categories( $post_id, $categories );
}
[/sourcecode]

It doesn’t add categories, it isn’t context-aware; it’s just a word-search. Just what I needed.

Share and Enjoy

  • Facebook
  • Twitter
  • Delicious
  • LinkedIn
  • StumbleUpon
  • Add to favorites
  • Email
  • RSS
Posted in codeRelease, life-of-a-geek, Software, wordpress, wordpressCode Tagged , , , , , , , , , Comments Off

Comments are closed.