subalbums next/prev album

amyg Member
Has anyone worked out a way to make the 'next and previous album' work with subalbums?
Right now, the links send me back to the main gallery page.
thanks in advance

Comments

  • Not sure exactly what you are saying, but you might want to check out the effervescence+simpleviewer theme. It has full paging of subalbums.
  • amyg Member
    Maybe I just needed sleep - I'll try it again - I'm pretty sure I tried with the E.S theme

    I want to use this function:
    http://www.zenphoto.org/trac/wiki/DeveloperReference#getNextAlbumURLandgetPrevAlbumURL

    But what happens is that instead of going to the next album - i end up back at the gallery index - or the next gallery.

    I just want users to be able to go album to album, with out having to go back to the index.
  • OK. That function does not yet support subalbums. So it is defaulting to the gallery. I took a quick look. The hack to provide subalbums is not hard, but also not trivial. You would have to make subalbum versions of `getNextAlbumURL`, `getPrevAlbumURL`, and the supporting routines: `getNextAlbum`, `getPrevAlbum`, `getAlbums` (you probably can use `getSubAlbums` for this), and `getAlbum`.
  • amyg Member
    OK - I'll try to get my head around that and give it a go
    thanks for getting back.
  • sbillard, I tried to use your code for ticket #2 here: http://www.zenphoto.org/trac/ticket/2 but I see now place to import
    subalbumfunctions.php

    I replaced my other 2 templates with yours and it doesnt break anything but I dont get to page either. Could you let me know what I am going wrong?!
  • Here is the code you need:
    `<?php<br />
    /** Next and Prev SubAlbum URLs */

    function getAlbumsCount() {

    global $_zp_current_album;

    $parentalbum = $_zp_current_album->getParent();

    $id = $parentalbum->getAlbumID();

    $sql = "SELECT COUNT(*) FROM ". prefix("albums") ." WHERE parentid = $id";

    $result = query($sql);

    $count = mysql_result($result, 0);

    return $count;

    }

    function getNextSubalbum() {

    global $_zp_current_album;

    $parent = $_zp_current_album->getParent();

    if (is_null($parent)) {

    $result = $_zp_current_album->getNextAlbum();

    if (!$result) {return null;} else {return $result;}

    }

    $subalbums = $parent->getSubAlbums(0);

    if (($inx = $_zp_current_album->index) == null)

    $inx = array_search($_zp_current_album->name, $subalbums);

    $inx = $inx+1;

    if ($inx >= 0 && $inx < getAlbumsCount()) {

    return new Album($parent, $subalbums[$inx]);

    } else {

    return null;

    }

    }

    function getPrevSubalbum() {

    global $_zp_current_album;

    $parent = $_zp_current_album->getParent();

    if (is_null($parent)) {

    $result = $_zp_current_album->getPrevAlbum();

    if (!$result) {return null;} else {return $result;}

    }

    $subalbums = $parent->getSubAlbums(0);

    if (($inx = $_zp_current_album->index) == null)

    $inx = array_search($_zp_current_album->name, $subalbums);

    $inx = $inx-1;

    if ($inx >= 0 && $inx < getAlbumsCount()) {

    return new Album($paraent, $subalbums[$inx]);

    } else {

    return null;

    }

    }

    function hasPrevSubalbum() {

    if (is_null(getPrevSubalbum())) {return false;}

    return true;

    }

    function hasNextSubalbum() {

    if (is_null(getNextSubalbum())) {return false;}

    return true;

    }

    function getNextSubAlbumURL() {

    if(!in_context(ZP_ALBUM)) return false;

    $nextalbum = getNextSubalbum();

    return rewrite_path("/" . pathurlencode($nextalbum->name),

    "/index.php?album=" . urlencode($nextalbum->name));

    }

    function getPrevSubAlbumURL() {

    if(!in_context(ZP_ALBUM)) return false;

    $prevalbum = getPrevSubalbum();

    return rewrite_path("/" . pathurlencode($prevalbum->name),

    "/index.php?album=" . urlencode($prevalbum->name));

    }

    ?>`

    put this into your custom-functions.php
  • amyg Member
    lovely!
    Thanks again sbillard
Sign In or Register to comment.