Wednesday, February 23, 2011

The Dagon Design Sitemap Generator plug-in for wordpress and WP_Error

I've had some trouble with the Dagon Design Sitemap Generator for Wordpress, version 3.15. When I installed it for my Wordpress 3.0 installation, I got an error on the page.

The error message i got was: Catchable fatal error: Object of class WP_Error could not be converted to string in .. \wp-content\plugins\sitemap-generator\sitemap-generator.php on line 513

It seems like I'm not the only one who has this problem when I googled for 'sitemap-generator.php on line 513'. Neither has the founder of the plug-in updated it lately so there seems like there is no update for this problem.

However I've found an solution or rather work around to this problem that seems to work.

What to do is to modify the PHP code with just a few lines.
The original code was on line 513:
return DDSG_CAT_HEADER . ' < a href="' . get_category_link($post_data[$p]['id']) . '" title="' . strip_tags($post_data[$p]['title']) . '">' . $post_data[$p]['title'] . '< /a>';

Now the modifications that needs to be done are:

if(is_string($p))
return DDSG_CAT_HEADER . ' < a href="' . get_category_link($post_data[$p]['id']) . '" title="' . strip_tags($post_data[$p]['title']) . '">' . $post_data[$p]['title'] . '< /a>';
else
return false;


The only thing you need to do with this is to remove the white-spaces after '<' in the code because Blogger will treat that as a link so I had to make an space in between.

The problem seems to be empty categories, but I'm not sure.