Albums on image.php

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

  • Is it possible that the next_ablum is looking for subalbums now, instead of albums?
  • I have exactly the same question. I am using a dropdown jump menu for quick links nav menu which is outputted on every page(image.php, index.php and albums.php).

    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
  • The weirdest part to me is that I created a new page (of my own) and the album listing is working great on that page. Maybe I can solve it that way...?
  • Okay found it.

    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);
    }
  • Thanks kiddomono, that worked for me.

    Kudos to you!
  • trisweb Administrator
    DANGER: That change disables sub-albums.

    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...
  • Thanks for your help Tris!

    I will make the relevant changes.
  • Aha, even better, thx for the help!
    (But I didn't need subalbums in this project anyway...)
  • So, how do I list the subalbums on the image.php page??
  • trisweb Administrator
    you should just be able to call `while(next_album()):` like in the album page... I think that'll do it...
  • I've tried this, but it doesn't work:

    `<? set_context(ZP_ALBUM); ?>

    <?php while (next_album()): ?>

    " title="Show Album: <?=getAlbumTitle();?>"><?php printAlbumTitle(); ?>

    <?php endwhile; ?>`
  • simon Member
    I used the following in conjuction with a drop down jump menu, which works fine. You can cut away the bits of form etc. -> should give you something which works in context.
    `





    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





    `

  • protum Member
    I too am looking to list sub-albums in image.php...but havent had any luck...

    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!
  • protum Member
    anybody?

    also, i'd like to list albums and subalbums on the index.php page
  • I too am trying to list in image.php the subalbums of the image's immediate parent album. Not having much like, like protum. :(

    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.
  • acrylian Administrator, Developer
    Take a look at the function print_album_menu.php that is located in the zp-core/plugins folder of your zenphoto installations. Move the file to your theme's folder and call it in the head with `require_once('print_album_menu.php')`.

    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.
  • Unfortunately printAlbumMenu() outputs a menu of all the albums and subalbums in your gallery it seems. I wish to only list the subalbums that are one level above the image I am viewing.

    I will play with it to see if I can modify for my needs. Thanks.
  • acrylian Administrator, Developer
    teedog:
    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]."
    • ";
      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 "
    • ".$subtitle[$nr2]."
    • "; }
      else
      { echo "
    • ".$subtitle[$nr2]."".$subimagecount[$nr2]."
    • "; }
      }
      } // 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]."
    • "; }
      } // 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 "
    • ".$subtitle[$nr2]."".$subimagecount[$nr2]."
    • "; }
      else
      { echo "
    • ".$subtitle[$nr2]."".$subimagecount[$nr2]."
    • "; }
      } // end if
      } // end for
      echo "
    ";

    } // end if

    // main album loop end

    }

    }

    ; ?>

    `
  • Your function uses "getIDForAlbum", I think this has to be getAlbumId. Anyways, great function! Exactly what i'm looking for here: http://www.zenphoto.org/support/topic.php?id=1883&replies=7
  • acrylian Administrator, Developer
    Right, getAlbumID() of course! getIDforAlbum() was a doubled function that we got rid of in 1.1. As I said it's been a while I made this...
  • Thanks acrylian. Again, I'm just blown away by how far each of the zenphoto devs here go to help users. :) Don't have time to read through your function right now but will do later.

    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 />
    }

    ?>

    `
  • acrylian Administrator, Developer
    Teedog:
    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...
  • Hmm I copied and pasted from my PHP file. Wonder if I messed something up when changing superficial text and variable names around. Anyway, not sure how adaptable/useful my function is to other people. It only outputs subalbums sharing the same parent in a dropdown menu. I can attach my file to Trac or something if you'd like.
  • acrylian Administrator, Developer
    Just wanted to tell: I found an error that prevented the display:
    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.
Sign In or Register to comment.