Just going to paste a quick code snippet here. Hopefully, this is part one of a series of tutorials/snippets to show you how to use WordPress as a CMS to power a Flash frontend photo gallery.
All you need to do is to to upload this file into the wp-content/plugins/nextgen-gallery/xml folder.
Code here:
<?php
/*
//----------------------------------------------------------------+
CUSTOM XML FOR NEXTGEN GALLERY
By Edwin Toh (www.designfission.com)
//----------------------------------------------------------------+
*/
if ( !defined('ABSPATH') )
require_once( dirname(__FILE__) . '/../ngg-config.php');
global $wpdb, $ngg, $nggdb, $wp_query;
$gallerylist = $nggdb->find_all_galleries('gid', 'asc', TRUE, 25, $start, false);
$ngg_options = get_option ('ngg_options');
$siteurl = site_url();
// get the gallery id
$galleryID = (int) $_GET['gid'];
// get the pictures
if ($galleryID == 0) {
$thepictures = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE tt.exclude != 1 ORDER BY tt.{$ngg_options['galSort']} {$ngg_options['galSortDir']} ");
} else {
$thepictures = $wpdb->get_results("SELECT t.*, tt.* FROM $wpdb->nggallery AS t INNER JOIN $wpdb->nggpictures AS tt ON t.gid = tt.galleryid WHERE t.gid = '$galleryID' AND tt.exclude != 1 ORDER BY tt.{$ngg_options['galSort']} {$ngg_options['galSortDir']} ");
}
// Create XML output
header("content-type:text/xml;charset=utf-8");
echo "<album>\n";
$gallerylist = $nggdb->find_all_galleries('gid', 'asc', TRUE, 0, 0, false);
if($gallerylist) {
foreach($gallerylist as $gallery) {
$class = ( !isset($class) || $class == 'class="alternate"' ) ? '' : 'class="alternate"';
$gid = $gallery->gid;
$name = (empty($gallery->title) ) ? $gallery->name : $gallery->title;
$author_user = get_userdata( (int) $gallery->author );
$picturelist = $nggdb->get_gallery($gid, $ngg->options['galSort'], $ngg->options['galSortDir'], false, 50, $start );
echo " <gallery>\n";
echo " <title>".stripslashes($name)."</title>\n";
echo " <description>".$gallery->galdesc."</description>\n";
if (is_array ($picturelist)){
foreach ($picturelist as $picture) {
echo " <image>\n";
echo " <title>".$picture->alttext."</title>\n";
echo " <description>".$picture->description."</description>\n";
echo " <url>".$siteurl."/".$picture->path."/".$picture->filename."</url>\n";
echo " <thumbnail>" . esc_url(nggGallery::i18n($picture->thumbURL)) ."</thumbnail>\n";
echo " </image>\n";
}
}
echo " </gallery>\n";
}
}
echo "</album>\n";
?>
casey yee says:
This is exactly what i’m looking for, but once i install it, how do i use it? presumably i enter a url of sort to get the xml output? please let me know!
thanks
January 21, 2011 at 8:15 am