Happy Birthday, me!
Here are a couple photos from today & yesterday, just to remind myself in years to come :]








WordPress: Custom Category Lists
WordPress has a category list widget which you can use to show all the used categories on your blog, you can even style it via CSS to make it pretty but sometimes designers like to make it hard for you and be all ” no don’t use images, because then we need to scale them for iPhone & iPad retina display, just use a symbols font for that! ” Crazy.
So heres a categories list, just like the widget, but you can style it or change the HTML in any way you like!
$args = array('orderby' => 'name', 'order' => 'ASC');
$categories = get_categories($args);
foreach($categories as $category) {
echo '<li><a href="'.get_category_link($category->cat_ID).'" class="mage"><span class="icon">)</span> '.$category->cat_name.'</a></li>';
}
via Inigo Media
Alternative to Sessions within WordPress
Nobody told me that WordPress total jacks up the globals making it near impossible for you to register sessions within WordPress. I tried a couple hacks to enable it via functions.php, I even went as far as ripping out code from the core to get it to work!
In a Google search I stumbled upon the Transient API – oh lordy, yes!
So custom sessions aren’t working for me, transients are the next best thing, they are super easy too!
## STORE TEXT set_transient($myvar, 'text I want to store', 60*60*12); ## RETRIEVE TEXT echo get_transient($myvar); ## DELETE THE TEXT delete_transient($myvar);
All my troubles seem so far away!
Increase/Decrease the word count in the_excerpt()
Heres one I’d been needing for a while but didn’t scratch my head hard enough.. Increasing/decreasing the word count in the WordPress excerpt. Very useful!
add_filter('excerpt_length', 'my_excerpt_length');
function my_excerpt_length($length) {
return 60;
}
WordPress Import Hack – Quick & Dirty
After finally convincing a client of mine to replace their existing 6 year old, custom built, extremely limiting & buggy blog software I’ve had to put in a bit of effort to transfer there 150+ blog posts from the MySQL table into WordPresses MySQL tables, which is pretty straight forward; the key here is to keep all of there featured images in place.
The following code does just that. It takes all the posts from the current blog, imports them into WordPresses tables, it inserts the featured image and then links it to the parent post. All thats then left to do is upload the images directory to WordPresses upload dir.
## DATABASE CONNECTION
// trololol you don't get to see this :]
## CLEAN URLS PLEASE
function toAscii($str) {
$clean = preg_replace("/[^a-zA-Z0-9\/_|+ -]/", '', $str);
$clean = strtolower(trim($clean, '-'));
$clean = preg_replace("/[\/_|+ -]+/", '-', $clean);
return $clean;
}
## SELECT THE BLOG DATABASE TO IMPORT, ORDER IT BY ID ASC (OR BY DATE ASC W/E)
$blog_q = mysql_query("SELECT * FROM `blog` ORDER BY `ID` ASC");
while($blog = mysql_fetch_array($blog_q)):
## INSERT POST INTO WORDPRESS
mysql_query("INSERT INTO `wp_posts` (
`post_author`,
`post_date`,
`post_date_gmt`,
`post_content`,
`post_title`,
`post_excerpt`,
`post_status`,
`comment_status`,
`ping_status`,
`post_password`,
`post_name`,
`to_ping`,
`pinged`,
`post_modified`,
`post_modified_gmt`,
`post_content_filtered`,
`post_parent`,
`guid`,
`menu_order`,
`post_type`,
`post_mime_type`,
`comment_count`) VALUES(
'1',
'".$blog['blogDATESUBMITTED']."',
'".$blog['blogDATESUBMITTED']."',
'".$blog['blogARTICLE']."',
'".$blog['blogTITLE']."',
'',
'publish',
'open',
'open',
'',
'".toAscii($blog['blogTITLE'])."',
'',
'',
'".$blog['blogDATESUBMITTED']."',
'".$blog['blogDATESUBMITTED']."',
'',
'0',
'',
'0',
'post',
'',
'0'
)");
## INSERT IMAGE INTO POSTS FEATURED IMAGE
mysql_query("INSERT INTO `wp_posts` (
`post_author`,
`post_date`,
`post_date_gmt`,
`post_content`,
`post_title`,
`post_excerpt`,
`post_status`,
`comment_status`,
`ping_status`,
`post_password`,
`post_name`,
`to_ping`,
`pinged`,
`post_modified`,
`post_modified_gmt`,
`post_content_filtered`,
`post_parent`,
`guid`,
`menu_order`,
`post_type`,
`post_mime_type`,
`comment_count`) VALUES(
'1',
'".$blog['blogDATESUBMITTED']."',
'".$blog['blogDATESUBMITTED']."',
'',
'".$blog['blogIMAGEALT']."',
'',
'inherit',
'open',
'open',
'',
'".toAscii($blog['blogIMAGEALT'])."',
'',
'',
'".$blog['blogDATESUBMITTED']."',
'".$blog['blogDATESUBMITTED']."',
'',
'".mysql_insert_id()."',
'http://www.newdomain.com/wp-content/uploads/2012/03/".$blog['blogIMAGE']."',
'0',
'attachment',
'image/jpeg',
'0'
)");
## LINK IT TOGETHER IN THE POST_META
mysql_query("INSERT INTO `wp_postmeta` (`post_id`, `meta_key`, `meta_value`) VALUES('".mysql_insert_id()."', '_wp_attached_file', '2012/03/".$blog['blogIMAGE']."')");
## AND SPIT OUT ONCE DONE….
echo $blog['ID'].' ---> '.$blog['blogTITLE'].'<br />';
endwhile; // end, select the blog database