I know this probably has been asked already somewhere, but I don't seem to find it... (And with the wiki still being down...) Anyway. I would like to list all albums on my image.php page (as text links). How can I do this? I was doing a simple copy/paste code method from the index.php, but it doesn't seem to be working. Any suggestions?
Thx.
Comments
Since updating to latest version 1.0.6 it only outputs the info on index.php.
Anyone tell me whats happened and how to fix it?
I am currently using the following code to print the relevant info which was working perfectly before:
<?php while (next_album()): ?>
<option value="<?=getAlbumLinkURL();?>"> <?php printAlbumTitle(); ?> </option>
<?php endwhile; ?>
Any help appreciated.
Simon
In the file "template-functions.php" (in the "zen" directory) you can find a function called "next_album" (somewhere around line 311).
The comments say: "If we're already in the album context, this is a sub-albums loop, which, quite simply, changes the source of the album list." So we need to change this again.
Change this part of the code:
if (in_context(ZP_ALBUM)) {
$_zp_albums = $_zp_current_album->getSubAlbums();
} else {
$_zp_albums = $_zp_gallery->getAlbums($_zp_page);
}
To this:
if (in_context(ZP_ALBUM)) {
//$_zp_albums = $_zp_current_album->getSubAlbums();
$_zp_albums = $_zp_gallery->getAlbums($_zp_page);
} else {
$_zp_albums = $_zp_gallery->getAlbums($_zp_page);
}
Kudos to you!
If you want to loop the root albums, just set the context before calling the function:
`set_context(ZP_INDEX);
while (next_album()):
...
endwhile;
set_context(ZP_ALBUM);`
In the future maybe I'll make this an option of the next_album() function, something like `next_album($level=0)` for the root, `next_album($level=-1)` for the current level...
I will make the relevant changes.
(But I didn't need subalbums in this project anyway...)
`<? set_context(ZP_ALBUM); ?>
<?php while (next_album()): ?>
" title="Show Album: <?=getAlbumTitle();?>"><?php printAlbumTitle(); ?>
<?php endwhile; ?>`
`
Choose a gallery and click Go
<?php set_context(ZP_INDEX); while (next_album()): ?>
"> <?php printAlbumTitle(); ?>
<?php endwhile; set_context(ZP_IMAGE); ?>
/info.html"> Information and Links
`
I have no trouble listing parent albums in image.php with this code:
`<?php set_context(ZP_INDEX); while (next_album()): ?>
<?php printAlbumTitle(); ?>
<?php endwhile; set_context(ZP_IMAGE); ?>`
According to trisweb above, this should work to list subalbums in image.php
`<?php while (next_album()): ?>
<?php printAlbumTitle(); ?>
<?php endwhile; ?>`
But nothing appears--there should be a bunch of subalbums listed.. `printAlbumTitle()` alone, out of the while loop, manages to print the current subalbum title but i cant get the other subalbums to list.
This doesnt work either.
`<?php set_context(ZP_ALBUM); while (next_album()): ?>
<?php printAlbumTitle(); ?>
<?php endwhile; set_context(ZP_IMAGE); ?>`
It would be great if anyone could point me in the right direction on this. Thanks!
also, i'd like to list albums and subalbums on the index.php page
Here's an example:
AlbumB contains SubAlbum1, SubAlbum2, SubAlbum3.
I'm viewing Image5 in SubAlbum3.
I'm trying to make Image5's page show a dropdown menu that lists/links to SubAlbum1, SubAlbum2, SubAlbum3.
That does exactly what you want and works on index, album and image.php and has an option for a drop down menu. How to use it is included in the file as comments.
One drawback: The menu supports currently only one subalbum level. It will be expanded to support to all levels, but that may take a little time.
I will play with it to see if I can modify for my needs. Thanks.
I just rediscovered that I once made a function that lists subalbums when you are it's parent album, one of the subalbum or in an image of them. It's more a draft and unfortunatly only supports one subalbum level too (it was made for 1.0.8.2). But maybe it fits your needs, take a look:
`
<?php<br />
/* printSubAlbumMenu - custom function v1
Prints a list of the main album and currently avaiable subalbums only if you are in an album that has
subalbums or in on of the subalbums or the corresponding impage view.
To be used on album.php and image.php
Usage:
<?php printSubAlbumMenu($option,$id1,$active1); ?>
$option = "count" for image counter behind the subalbum name, "" for no image counter
The parameters are optional if you want specify CSS-IDs to style the menu. You can leave them blank, too.
$id1 = Insert here the ID for the main album menu like this.
$active1 = Insert the ID for the currently active album link
*/
function printSubAlbumMenu($option,$id1,$active1) {
if ($id1 != "") { $id1 = " id='".$id1."'"; }
if ($active1 != "") { $active1 = " id='".$active1."'"; }
// main album query
$sql = "SELECT id, parentid, folder, title FROM ". prefix('albums') ." WHERE parentid is NULL ORDER BY sort_order";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$number++;
$idnr[$number] = $row['id'];
$parentid[$number] = $row['parentid'];
$folder[$number] = $row['folder'];
$title[$number] = $row['title'];
switch($option) {
case "count":
// count images in the main albums
$sql = "SELECT COUNT(id) FROM ". prefix('images') ." WHERE albumid = $idnr[$number]";
$result2 = query($sql);
$count = mysql_result($result2, 0);
$imagecount[$number] = " (".$count.")";
}
}
// sub album query - possibly these two queries could be done better...
$sql = "SELECT id, parentid, folder, title FROM ". prefix('albums') ." WHERE parentid ORDER BY sort_order";
$result = mysql_query($sql);
while($row = mysql_fetch_array($result))
{
$subnumber++;
$subidnr[$subnumber] = $row['id'];
$subparentid[$subnumber] = $row['parentid'];
$subfolder[$subnumber] = $row['folder'];
$subtitle[$subnumber] = $row['title'];
switch($option) {
case "count":
// count images in the subalbums
$sql = "SELECT COUNT(id) FROM ". prefix('images') ." WHERE albumid = $subidnr[$subnumber]";
$result2 = query($sql);
$count2 = mysql_result($result2, 0);
$subimagecount[$subnumber] = " (".$count2.")";
}
}
// album view: list subalbums in this album
for ($nr = 1;$nr <= $number; $nr++) <br />
{
for ($nr2 = 1;$nr2 <= $subnumber; $nr2++) // Subalbum loop start<br />
{
if ($subparentid[$nr2] === getIDForAlbum() ) // check if subalbums avaiable, if not don't print anything
{
if(getIDForAlbum() === $idnr[$nr])
{ echo "
- ".$title[$nr]."".$imagecount[$nr]."
"; - ".$subtitle[$nr2]."
"; }- ".$subtitle[$nr2]."".$subimagecount[$nr2]."
"; }
";for ($nr2 = 1;$nr2 <= $subnumber; $nr2++) // Subalbum loop start<br />
{
if ($subparentid[$nr2] === getIDForAlbum() ) // print avaiable subalbums to current album
{
if ($subtitle[$nr2] === getAlbumTitle()) // check if active album
{ echo "
else
{ echo "
}
} // end for
echo "
} // end if
// main album loop end
}
}}
// subalbum and image view: list subalbums in this album
for ($nr = 1;$nr <= $subnumber; $nr++) <br />
{
if(getIDForAlbum() === $subidnr[$nr]) // get parentid of current subalbum and so the id of the parent album
{ $currentid = $subparentid[$nr];
for ($nr2 = 1;$nr2 <= $number; $nr2++) // Get parent album name<br />
{
if ($subparentid[$nr] === $idnr[$nr2])// print parent album
{ echo "
- ".$title[$nr2]."".$imagecount[$nr2]."
"; } - ".$subtitle[$nr2]."".$subimagecount[$nr2]."
"; }- ".$subtitle[$nr2]."".$subimagecount[$nr2]."
"; }
";} // end for
for ($nr2 = 1;$nr2 <= $subnumber; $nr2++) // Get subalbums<br />
{
if ($currentid == $subparentid[$nr2])// print subalbums
{
if ($subtitle[$nr2] === getAlbumTitle()) // check if active album
{ echo "
else
{ echo "
} // end if
} // end for
echo "
} // end if
// main album loop end
}
}
; ?>
`
Here's a function I hacked up to be used in image.php (and album.php I think) which displays a dropdown menu of subalbums with the same parent when you are in a subalbum. That is, if Album1 has Sub1, Sub2, Sub3, and you are viewing Sub2/Image2, this function lists Sub1, Sub2, Sub3.
I'm a total noob so feedback is welcome.
`
<?php<br />
function printAlbumMenu() {
if (getOption('mod_rewrite'))
{ $albumlinkpath = WEBPATH."/"; }
else
{ $albumlinkpath = "index.php?album="; }
$sql = "SELECT id, parentid, folder, title FROM ". prefix('albums') ." WHERE `show`= 1 ";
$result = mysql_query($sql);
$number = 0;
while($row = mysql_fetch_array($result)) {
$number++;
$parentid[$number] = $row['parentid'];
$folder[$number] = $row['folder'];
$title[$number] = $row['title'];
}
$my_album_title = getAlbumTitle();
$my_key = array_search($my_album_title, $title);
$my_parentid = $parentid[$my_key];
$my_folder_array = array();
for ($i=0; $i<$number; $i++) {<br />
if ($parentid[$i] == $my_parentid) {
$my_folder_array[] = $folder[$i];
if ($title[$i] == $my_album_title) {
$my_album_folder = $folder[$i];
}
}
}
sort($my_folder_array);
$current_folder_key = array_search($my_album_folder, $my_folder_array);
$my_array_count = count($my_folder_array);
?>
Select Subalbum
<?php<br />
for ($nr=0; $nr<$my_array_count; $nr++)<br />
{
$subalbum_number = $nr+1;
if ($nr == $current_folder_key) {
echo "Subalbum ".$subalbum_number."";
} else {
echo "Subalbum ".$subalbum_number."";
}
}
?>
<?php<br />
}
?>
`
I just did a quick test and have not really time to look into, but it shows no albums for me. Maybe just a typo while posting or so...
the "show" in the query needed to be escaped with backticks. Surely that happened when posting (the forum does these things...). It works exactly now as you said.
Maybe I can adapt this partly to the next print album menu version.