Something Old and New: Importing WordPress posts into Sitefinity

I can’t take too much credit for this, however, I made enough updates to the library that I felt it warranted a post.

If you’re migrating your blog from WordPress into Sitefinity, I’ve taken an existing tool (major HT to timw255) and modified it. I disabled some features with loading tags/metadata that caused errors. More importantly, I added the ability to have a “default” e-mail address, properly import the full image from the “thumbnail” images that WordPress typically uses, and cleaned up the summary field.

It’s on Github, so as they say, if you don’t like what I did, fork it and improve it yourself! 8^D

You can get the WordPress to Sitefinity tool here.

Continue reading “Something Old and New: Importing WordPress posts into Sitefinity”

Advertisement

How to Embed Full Page iFrames (with busting) in WordPress

Sometimes (at least I did) you need to embed a page (maybe even your own) in “full screen” within your WordPress site. The problem is that by default, you’ll have the header, footer, and any widgets also embedded in the site. This can cause some layout nightmares. However, here’s a trick I have put togetether to render these kind of pages and keep your links working properly.

Continue reading “How to Embed Full Page iFrames (with busting) in WordPress”

Quick Tip

Quick Tip: Bulk Edit Post Formats in WordPress

As you may have noticed, I recently merged my photo blog and quote blog here into my main blog. As part of that process, I wanted all of my photos to use the “gallery” post format to take advantage of its display options in the new twenty thirteen theme. When you’re in the main post editor, there’s not way to “bulk edit” post formats. Here’s a “back door” trick on how to get it done. Continue reading “Quick Tip: Bulk Edit Post Formats in WordPress”

Quick Tip: Fix old WordPress links with the Redirection plugin and the WayBack Machine

Quick Tip

I’ve been honored to be the webmaster over at Evangelical Outpost for a few years now. The site itself dates back to 2003, but I haven’t been around quite that long. Being that the site has changed owners, webmaster, and formats a couple of times, our permalink structure has changed a couple of times as well. As a result, we’re starting to find some 404 errors coming in from outside links. The old permalink format wasn’t in any form we could recognize (post ID, date code, title, etc.), and I was worried that they might be lost forever. However, thanks to two little features, Redirection and the WayBack Machine, we can now successfully get our links working again! Here’s how. Continue reading “Quick Tip: Fix old WordPress links with the Redirection plugin and the WayBack Machine”

Quick Tip: Check Your Mime Types in Internet Explorer and WordPress

This is a rather odd problem I ran into yesterday with a colleague that was worth sharing.

She had installed a WordPress plug-in that allowed you to replace existing files in your media library. This is a great feature for us since we are often updating the same newsletter item and don’t want to remove and re-add the file to the media gallery.

After installation, she went to replace an existing .jpg image and received the following error message:

File type does not meet security guidelines.

Digging into the plug-in, we found the code that generates this message. Continue reading “Quick Tip: Check Your Mime Types in Internet Explorer and WordPress”

Default Category Images for WordPress

I’ve been working on a news oriented WordPress site lately. One of the nice things with WordPress 2.9 and above was that they created a “thumbnail” feature, also known as “featured image” in 3.0+. With this feature you could display an image  related to the article to help preview it. Most sites you see now use this in conjunction with a “slider” on their home page.

In the site I’m working on, there isn’t a featured image for every single news item available. Sometimes the news item is simply a repeat of a notice from another source. Since the home page of the site looked for an image to display in its list, the page became unattractive since there were a lot of “no image available” boxes scattered on the page:

Site without categories
The site without category images (click for larger view).

The idea then arose about having an icon or default image for each category, and displaying that when an image was not available. Since I’m still honing my WordPress chops, so I needed to develop a solution that didn’t involve creating plugins and wasn’t too deeply embedded within the site that it would make it hard to update down the road. The home page has several widgets that retrieve the featured image in various formats (full, medium, small) so I needed to find a single point of entry in which to return the image, and let the theme do its own resizing.

The first step was to create the category images and place them into a folder called “category-images” under my “wp-content” folder of the site. The key here is to name the images the same as the “nice name” values for each of the categories. This typically means using all lower case and putting a “-“ in place of spaces, such as “prescribed-burns”. This makes it easier to generate the URL to the images in the code.

The next step is to find the code in my theme where the featured images were being retrieved for a given post. This is where you’re going to have to venture out on your own to implement this solution. [Psst, hey WordPress theme developers, this would be a great time to implement this into your theme so no fancy hackery is needed!] After some digging, I found the function that served as the central point for retrieving images that were displayed on the home page widgets:

function get_images($iPostID,$img_size='thumb')

{
   $arrImages =& get_children('order=ASC&orderby=menu_order ID&post_type=attachment&post_mime_type=image&post_parent=' . $iPostID );
   $return_arr = array();

   if($arrImages)
   {
      foreach($arrImages as $key=>$val)
      {
         $id = $val->ID;

         if($img_size == 'large')
         {
            $img_arr = wp_get_attachment_image_src($id,'full');
            $return_arr[] = $img_arr[0];
         }
         elseif($img_size == 'medium')
         {
            $img_arr = wp_get_attachment_image_src($id, 'medium');
            $return_arr[] = $img_arr[0];
         }
         elseif($img_size == 'thumb')
         {
            $img_arr = wp_get_attachment_image_src($id, 'thumbnail');
            $return_arr[] = $img_arr[0];
         }
      }
   }

   return $return_arr;
}

 

The trick to making this work was to add some additional code so that the category image URL would be generated in the even no images where found. The final code looks like this:


function get_images($iPostID,$img_size='thumb')

{
   $arrImages =& get_children('order=ASC&orderby=menu_order ID&post_type=attachment&post_mime_type=image&post_parent=' . $iPostID );
   $return_arr = array();

   if($arrImages)
   {
      foreach($arrImages as $key=>$val)
      {
         $id = $val->ID;

         if($img_size == 'large')
         {
            $img_arr = wp_get_attachment_image_src($id,'full');
            $return_arr[] = $img_arr[0];
         }
         elseif($img_size == 'medium')
         {
            $img_arr = wp_get_attachment_image_src($id, 'medium');
            $return_arr[] = $img_arr[0];
         }
         elseif($img_size == 'thumb')
         {
            $img_arr = wp_get_attachment_image_src($id, 'thumbnail');
            $return_arr[] = $img_arr[0];
         }
      }
   }
   else
   {
      $category = get_the_category($iPostID);

      // if the category has no parents, use its nicename for a proper URL, otherwise use the parent category name (such as fires)
      if ($category[0]->category_parent == 0)
      {
         $return_arr[0] = site_url('/wp-content/category-images/', '') . $category[0]->category_nicename . '.jpg';
      }
      else
      {
         $parent = get_category($category[0]->category_parent);
         $return_arr[0] = site_url('/wp-content/category-images/', '') . $parent->category_nicename . '.jpg';
      }
   }

   return $return_arr;
}

WordPress makes it easy to retrieve category, and even parent category information for the post, and we use as much built in methods as possible so that the URL to the images changes easily if the site changes.

Site with categories.
The site with category images (click for larger view).

I’ve seen a few WordPress plugins to assign images to a category, but they were going to be more trouble than it was worth to integrate it into the current theme. Hopefully this gives you a direction to look at if you need to setup category images for your site, or maybe it’ll inspire a WordPress theme creator out there to build this in to the next theme they create. I’m sure there are plenty of sites that can benefit from this.

Review: Head First WordPress

HeadFirstWordPressCover

I’m a seasoned web developer that has been working a little bit with WordPress over the past 6 months. I’ve read books in the “Head First” series before, so when I discovered that there was a WordPress edition, I grabbed it without hesitation. Head First WordPress by Jeff Siarto (HWP) provides an excellent introduction into the WordPress environment.

The book is structured to teach you how WordPress works while simultaneously having you build a couple of fictional WordPress sites. As you’re reading, numerous tips, facts, and humorous asides are annotated throughout the book. This is what makes “Head First” an excellent series of books. It engages your mind while teaching you “tech” things that can be boring to a lot of people.  HWP demonstrates how WordPress can be used for a simple content site, such as a business, or for a magazine/journal type site, which has frequent posts by various authors. While HWP doesn’t go too deep with any particular topic, it does make sure to touch the wide variety of concepts involved with a WordPress site: installation, theming, metadata (categories and tags), creating/editing pages, plugins, users, securing your blog, and more. By the end of the book you will have a good grasp on what WordPress can do for you, a working site that you can work with to customize as you see fit, as well as some additional topics to look into for further study (listed in the “Leftovers” appendix).

While the entire book is geared towards those that have basic web hosting experience, I found the first chapter might be a little intimidating to those users. The chapter outlines a full WordPress install, including FTP transfers, file permissions, and database setups. If you have the “quick install” option available, I suggest you use it. Otherwise, take the time and work through the install, since after that the rest of the book is a lot easier by comparison.

I also want to point out that chapter 5, involving videos and plugins, was my favorite chapter. It did a fantastic job and explaining how plugins and embedded videos work in a WordPress site. The chapter also involved a little bit of customization to the site to easily embed videos and to clean up your home page so that the entire post is not displayed. The author did a great job of explaining these concepts in an easy to understand manner.

Head First WordPress is an excellent book and I highly recommend it to anybody looking to get involved with this popular platform. You can view a preview of the book by going to the O’Reilly site at http://oreilly.com/catalog/9780596806286/.

Announcing Blog Migrator

Taken from the CodePlex site where I’ve published things:

The Blog Migrator tool is an all purpose utility designed to help transition a blog from one platform to another. It leverages XML-RPC, BlogML, and WordPress WXR formats. It also provides the ability to “rewrite” your posts on your old blog to point to the new location.

The Blog Migrator started out as a bounty by Roy Osherove looking for a way to migrate out from the weblogs.asp.net site into SquareSpace. By default, SquareSpace did not have an automatic import tool for BlogML generated export files. Thus this project was born.

Blog Migrator can handle both simple (only post) migrations and complete (posts, comments, etc.) depending on which format you use. Blog Migrator can read BlogML dumped files or connect directly to your site via XML-RPC. You can publish to your new site via XML-RPC, or generate a WordPress WXR document, which is widely used by numerous blog services to import content. One of the most handy features of Blog Migrator is the ability to update your “source” blog posts to point to the destination blog, thus helping your users know of your new location.

While functional, there are lots of additional features that can be added (Movable Type/Blogger format support, previews of source/destination content). You are encouraged to help make this tool even better by taking the source, looking at features/bugs, and improve things even more!

Enjoy! And thanks to Roy Osherove for giving me this opportunity!

Migrating BlogML to WordPress 3.0

Update (1/18/2013): An amazing developer by the name of Patrick Daly has updated this plugin through GitHub to import tags too. Go grab it here!

Update: My plugin has been approved by WordPress! I’ve updated the documentation and links accordingly.

As part of my migration to WordPress 3.0, I needed to get all of my posts migrated over. My comments were stored via Disqus, and I’m working with them on migrating that data to the new URL slugs.

BlogEngine.Net uses BlogML as their sole export format, which became a little tricky, since there is still no WordPress importer built in to handle this.

As is with most things in life, we are all standing on the shoulders of giants. In this case, Aaron Lerch was my giant and he had created a great BlogML importer, which included all of the necessary XPath information needed to import blog entries.

The only problem is that the plugin was created to work with WordPress 2.6, and the format for importing content has changed since then. The  ‘wp-admin/imports’ folder no longer exists in 3.0, and it could have been earlier than that as well.

An initial peek of the importer code didn’t yield any results to me, but installing the simple RSS importer and examining that code allowed me to see what was going on. With the newer format for importing, you downloaded a plugin, which upon activation registered itself with the import module used in WordPress. All I needed to do was to put this registration wrapper around the existing code, update some documentation, and voila, a working BlogML importer!

Just as my giant has opened the code up, I’m doing the same, for any BlogEngine.Net,  SubText, or other BlogML formatted folks out there that are thinking of migrating to WordPress.

Before importing, you’ll want to go into your BlogML file and look for any file or image references that exist and update them accordingly. For instance, with BlogEngine.Net, it uses a ‘file.axd’ HTTP helper to deliver a lot of its files. You can always update this data after the import. It is up to you.

Using the importer is rather simple:

  1. Log into your WordPress site and go to the ‘Plugins’ section.
  2. Click the “Add New” button and search for the term “blogml”.
  3. Find the ‘blogml-importer’ plugin and install it.
  4. Activate the plugin.
  5. Go to the Tools->Import screen, and select the ‘BlogML’ option.
  6. Follow the directions to complete the process.

As an added bonus (thanks to Aaron), the import process will create a CSV file that maps the old permalinks found in the BlogML file to the new permalinks that WordPress generated. It will also give you the option of mapping posts to a current user, or to create a new user account for them.

I ran this process and had all of my posts migrated over in a few seconds. Granted I only had 65 posts, but it still saved me a lot of time. I’m still doing a bit of image/link cleanup, but that is simple to do.

One other important item to note is that categories and tags may or may not be properly imported. In my case, none of my tags came over, and my categories came over named as GUIDs. Renaming the categories didn’t take long and I’ll simply need to retag my posts. Again, considering the time it would have taken me to renter all of my posts (and I know others have lots more), I’m not too worried about this.

I hope this helps other folks out their with their WordPress migrations. I’m hoping to look through the import code again, and work on getting some of the category/tag issues resolved. I may even try to do some kind of auto-detecting on the image/file links to provide a proper “remap” option like with the user import. Once the plugin is approved in the codex, I’ll update my link to point there.

Enjoy!

If you want to download the plugin go to the direct link here.

UPDATE: If you want a standalone tool that will migrate BlogML to WordPress, check out the Blog Migration Tool I wrote over on CodePlex.

Bienvenue WordPress!

Well, here I am on WordPress 3.0.

Some of you may be wondering why I’m rolling a new blog engine, and a PHP based one at that [yeah Mr. .Net Junkie!].

I have nothing against BlogEngine. I love it. I recommend it for any .Net folks out there that want to do get into blogging and tweak with their themes/plugins a bit. You’ll feel quite at home there. I was impressed with the layout of it when I went through the process of migrating Disqus into my theme.

Lately though, my side work has drifted into the realm of WordPress (through my support of Evangelical Outpost as well as some upcoming work with The Prescott Project). I felt it best if I could get some more hands on work with WordPress and PHP. As they say, “Never stop learning” right? I’ve already gotten back in the groove a bit by modifying a BlogML import script out there to work with 3.0 so I could migrate my posts in. More details on that later.

Enjoy!