code in the function.php
`
<?php
/* * Connect to the Zenphoto database on a Wordpress template file.*/
$conf['mysql_user'] = 'xxxxx';
$conf['mysql_pass'] = 'xxxxxx';
$conf['mysql_host'] = 'localhost'; // Won't need to change this 90% of the time.
$conf['mysql_database'] = 'xxxxxx';
function connectZenphotoDB($host,$user,$pass,$db) {
// mysql connection
$mysqlcon = @mysql_connect($host,$user,$pass);
if(!$mysqlcon) {
die("Could not connect - Query failed : " . mysql_error());
}
if(!@mysql_select_db($db)) {
die("db could not be selected - Query failed : " . mysql_error());
}
}
/**
* Print the thumb of the latest image of an album from the zenphoto image cache directly on a Wordpress page template file.
* This function does not do any image processing!
*
* This assumes Wordpress is installed in the root and Zenphoto within a folder $zenphotopath.
*
* @param string $albumname folder name of the album (note subalbums names contain the parents!: toplevel/sub)
* @param string $zenphotopath the path to the Zenphoto installation with trailing slash (/zenphoto)
* @param string $albumsdbtable the albums table, don't forget the prefix!
* @param string $imagesdbtable the images table, don't forget the prefix!
*/
function printLatestZenphotoImageFromAlbum($albumname="Nuova Cartella",$zenphotopath="http://www.ziguline.com/gallery",$albumsdbtable="zp_albums",$imagesdbtable="zp_images") {
$albumid = "";
// getting the id of the album chosen
$albumquery = "SELECT [code][/code]id[code]FROM[/code]".$albumsdbtable."[code]WHERE[/code]folder[code]= '".$albumname."' ORDER BY[/code]id
`
DESC";
$albumresult = mysql_query($albumquery) or die("Query failed : " . mysql_error());
$albumid = mysql_fetch_row($albumresult);
$albid = $albumid[0];
$title = "";
$folder = $albumname;
// getting latest image from the album
$imagequery = "SELECT `filename`,`title`,`desc` FROM `".$imagesdbtable."` WHERE `albumid` = ".$albid." ORDER BY `id` DESC LIMIT 1";
$imageresult = mysql_query($imagequery) or die("Image query failed : " . mysql_error());
$image = mysql_fetch_row($imageresult);
//echo "Latest image: "; print_r($image); echo "";
$imagename = explode(".",$image[0]);
// echo "Image: ".$imagename[0]." / suffix: ".$imagename[1];
// if "showcase" use title of latest images else the one of the latest album of this section
$title = $image[1];
// print the image from Zenphoto's image cache if it exists, else print a replacement one from the theme
// The file name must exactly fit, so be sure to change the "w238_h128_cw238_ch128" part to the actual dimensions
// of your thumbs in the cache or implement some image processing here
if(file_exists($zenphotopath.'cache/'.$folder.'/'.$imagename[0].'_w238_h128_cw238_ch128_thumb.'.$imagename[1])) {
echo '<img src="'.$zenphotopath.'cache/'.$folder.'/'.$imagename[0].'_w238_h128_cw238_ch128_thumb.'.$imagename[1].'" alt="'.$title.'" />';
} else {
// if no image in the cache has been found load a fixed replacement image, show a message or whatever else
echo "Sorry, no image found in cache...";
}
}
define('DEBUG_ERROR', true); // set to true to supplies the calling sequence with zp_error
?>
and then in the index.php of my theme:
`<?php printLatestZenphotoImageFromAlbum();?>`