Tag Archives: WordPress

WordPress for iOS 3.1

20120809-110445 PM.jpg

Matt mentioned these updates in State of the Word 2012 and its just been released. It’s pretty amazing now!

WP Canvas

About this time last year I made a canvas with a QR code on it, it hangs proudly in my office. I had bought two canvases then but only used one. Today I had an idea for the second!

WP Canvas! – It only took 20 minutes to make and I think it turned out well. Thoughts?

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!

[php]
$args = array(‘orderby’ => ‘name’, ‘order’ => ‘ASC’);
$categories = get_categories($args);
foreach($categories as $category) {
echo ‘

  • ) ‘.$category->cat_name.’
  • ‘;
    }
    [/php]

    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!

    [php]
    ## 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);
    [/php]

    All my troubles seem so far away!

    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.

    [php]
    ## 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’].’
    ‘;

    endwhile; // end, select the blog database

    [/php]