<?php 
require('./wp-config.php');
header('Content-type: text/xml; charset=utf-8');

function 
ssp_fetch_images($postid$size) {
    global 
$wpdb;
    return 
$wpdb->get_results("SELECT guid, post_title, post_content FROM $wpdb->posts WHERE post_parent = $postid AND post_mime_type = 'image/jpeg'");
}

$exclude $_GET['exclude'];
$exclusions '';
if ( !empty(
$exclude) ) {
    
$excats preg_split('/[\s,]+/',$exclude);
    if ( 
count($excats) ) {
        foreach ( 
$excats as $excat ) {
            
$exclusions .= ' AND cat_ID <> ' intval($excat) . ' ';
        }
    }
?>
<gallery>
    <?php $categories $wpdb->get_results("SELECT cat_ID, cat_name, category_description FROM $wpdb->categories WHERE cat_ID > 0 $exclusions ORDER BY cat_ID");
    foreach(
$categories as $cat) { ?>
    <album title="<?php echo $cat->cat_name?>" description="<?php echo $cat->category_description?>">
        <?php $gallery = new WP_Query("cat=$cat->cat_ID&showposts=1000");
        while (
$gallery->have_posts()) : $gallery->the_post();
        
$images ssp_fetch_images($post->ID);
        foreach(
$images as $image) { ?>
        <img src="<?php echo $image->guid?>" tn="<?php echo str_replace(".jpg"".thumbnail.jpg"$image->guid); ?>" title="<?php echo htmlspecialchars($image->post_title); ?>" caption="<?php echo htmlspecialchars($image->post_content); ?>" link="<?php the_permalink(); ?>" />
        <?php } endwhile; ?>
    </album>
    <?php ?>
</gallery>