In my current theme, I use:
<?php if (getNumImages() > 0): /* Only print if we have images. */ ?>
to check if there are images in this album. Is getNumAlbums the equivalent to see if the album has subalbums ? If not, is there an equivalent ?
It seems getNumbAlbums returns the total number of albums, without context.
Comments
I display on the main index a count of albums and subalbums total, then in each album (mouse over each album image) it will display a count of how many images in the root album + how many subalbums there are.
Is that close to what you were looking for? If so, I'd happy to post the code.
The Latest Images and Subalbums are easy. The Most Popular and Highest Rated involve minor database changes, relating to hit counts and star rating systems, both of which have forum posts here. Still interested? The only reason I ask is that some people don't want to modify their DB. I'll have to package them up for you too, because it involves a few files, and then some DB changes, and then some CSS tweaking, and etc....
Here's the counting functions:
`/* SQL Counting Functions */
function show_subalbum_count() {
$sql = "SELECT COUNT(id) FROM ". prefix("albums") ." WHERE parentid <> \"NULL\"";
$result = query($sql);
$count = mysql_result($result, 0);
echo $count;
}
function getIDforAlbum() {
if(!in_context(ZP_ALBUM)) return false;
global $_zp_current_album;
return $_zp_current_album->getAlbumID();
}
function show_sub_count_index() {
$id = getIDforAlbum();
$sql = "SELECT COUNT(*) FROM ". prefix("albums") ." WHERE parentid = $id";
$result = query($sql);
$count = mysql_result($result, 0);
echo $count;
}`
Now mind, the latest albums/subalbums and the latest images were not developed by me but by this nice gentleman here, and I tweaked them a bit. But these are the functions. Don't forget the Most Popular and Highest Rated require additional work, so don't call them unless you have the changes in place mentioned above, but basically they are just versions of the latest images.
`/* Show Latest Albums */
/* http://anton.gektoras.lt/zenphoto/zenphoto-latest-albums */
function show_latest_album($number) {
$sql = "SELECT * FROM ". prefix("albums") ." ORDER BY id DESC LIMIT $number";
$result = mysql_query($sql);
while($r = mysql_fetch_array($result)) {
if ($r['thumb']==NULL) {
$image = get_album_image($r['id']);
} else {
$image = $r['thumb'];
}
echo '';
if (zp_conf('mod_rewrite') == false) {
echo '';
echo '';
// echo '
'.$r['title'].'
';} else {
echo '';
echo '';
// echo '
'.$r['title'].'
';}
echo '';
}
}
function get_album_image($id) {
$sql = "SELECT * FROM ". prefix("images") ." WHERE albumid = $id";
$result = mysql_query($sql);
while($r = mysql_fetch_array($result)) {
return $r['filename'];
}
}`
`/* Show Latest Images */
/* http://anton.gektoras.lt/zenphoto/zenphoto-latest-images */
function show_latest_images($number) {
$images = query_full_array("SELECT images.albumid, images.filename AS filename, images.title AS title, albums.folder AS folder FROM ".prefix('images')." AS images, ".prefix('albums')." AS albums WHERE images.albumid = albums.id AND images.show = 1 ORDER BY images.id DESC LIMIT $number");
$size = '_'.zp_conf('thumb_size').'_cw'.zp_conf('thumb_crop_width').'_ch'.zp_conf('thumb_crop_height');
foreach ($images as $image) {
$filename = $image['filename'];
$album = $image['folder'];
$desc = $image['title'];
echo '';
if (zp_conf('mod_rewrite') == false) {
echo '';
} else {
echo '';
}
/* echo ''; */
echo '';
echo '';
}
}
/* Show Most Popular Images */
';/* Modified from show_latest_images from http://anton.gektoras.lt/zenphoto/zenphoto-latest-images */
function show_most_popular($number) {
$images = query_full_array("SELECT images.albumid, images.filename AS filename, images.title AS title, images.hit AS hit, albums.folder AS folder FROM ".prefix('images')." AS images, ".prefix('albums')." AS albums WHERE images.albumid = albums.id AND images.show = 1 ORDER BY images.hit DESC LIMIT $number");
$size = '_'.zp_conf('thumb_size').'_cw'.zp_conf('thumb_crop_width').'_ch'.zp_conf('thumb_crop_height');
foreach ($images as $image) {
$filename = $image['filename'];
$album = $image['folder'];
$desc = $image['title'];
$hit = $image['hit'];
echo '
if (zp_conf('mod_rewrite') == false) {
echo '';
} else {
echo '';
}
echo '';
echo '';
}
}
/* Show Highest Rated Images */
';/* Modified from show_latest_images from http://anton.gektoras.lt/zenphoto/zenphoto-latest-images */
function show_highest_rated($number) {
$images = query_full_array("SELECT images.albumid, images.filename AS filename, images.title AS title, images.total_value AS totalvalue, images.total_votes as votes, albums.folder AS folder FROM ".prefix('images')." AS images, ".prefix('albums')." AS albums WHERE images.albumid = albums.id AND images.show = 1 ORDER BY (images.total_value/images.total_votes) DESC LIMIT $number");
$size = '_'.zp_conf('thumb_size').'_cw'.zp_conf('thumb_crop_width').'_ch'.zp_conf('thumb_crop_height');
foreach ($images as $image) {
$filename = $image['filename'];
$album = $image['folder'];
$desc = $image['title'];
$totalvalue = @number_format($image['totalvalue']/$image['votes'],2);
echo '
if (zp_conf('mod_rewrite') == false) {
echo '';
} else {
echo '';
}
echo '';
echo '';
}
}`
`include(__FILE__ . "/customfunctions.php")`
at the top of your theme pages where you use the functions. That way we don't get into modifying zenphoto's actual code.
I could even come up with a convention, and always include a 'hacks.php' if it's present in the theme, or any name you guys want... It would be nice before we have a plugin system I think.
A hacks.php file would be a great thing to include in the base files, so that you can just store your stuff in that file in your theme.
This makes it a lot quicker and cleaner when doing upgrades too.
Can't wait for plugins, then I can get the custom code out of the i.php file, and then none of my mods affect any of the zen core files.
The only other thing to note is about custom DB changes. How would that work? e.g. the rating system and hit count require DB changes, so you'd have to come up with some sort of plugin modification system like Wordpress has to make changes to the DB, which I guess could be done during plugin load (does that make sense?)