How do I keep empty albums from showing up in the search page?

Maccus Member
Hi, I am trying to theme a stockphoto site with ZenPhoto.

I have many subalbums, and the thing is that when I do a search, I don't want the albums with no images in them to show up in the search page.

I actually managed to do that in this way:

`<?php while (next_album()): $c++; ?>`
`<?php if (getNumImages() !=0) : ;?>`

Here comes the album thumb...

`<?php endif; ?>`
`<?php endwhile; ?>`

But the problem is that I configured my theme to show six albums per page. But on the page is only two albums visible. The other four albums (with no images in them) just seem to occupy empty space. How can I fix that ?

This is the site as it is now:

http://maccusfoto.nl/zenphoto/page/search/fields255/roma

When you click the navigation you can see six albums divided over 2 pages, while they really should be on one page...

TIA, Max

Comments

  • You will have to handle the pagination yourself since Zenphoto does not know you are not going to display some of the albums.

    I have not tried the following, but think it would work.

    Place the code before your `while (next_album())` loop.

    `
    $_zp_albums = $_zp_current_search->getAlbums(0);
    foreach ($_zp_albums as $key=>$albumname) {
    $album = new Album($_zp_gallery, $albumname;
    if ($album->getNumImages() == 0) {
    unset($_zp_albums[$key]);
    }
    }
    `
    Then use the normal next_album() loop. The above code will remove all albums from the cache array which have no images. The next_album() loop uses the cache array if it is populated.
  • Maccus Member
    Thanks for your reply,

    This code works!

    But:

    * The albumname has now disappeared (I use printbreadcrumb).

    * When I use the searchbutton without putting text in the searchbox it generates an error:

    Notice: Undefined variable: albumname in /storage/mijndomein/users/041181/public/sites/www.maccusfoto.nl/zenphoto/themes/maccus/search.php on line 40

    * The `while (next_image)` loop below the album loop now generates an error:

    Fatal error: Call to a member function isDynamic() on a non-object in /storage/mijndomein/users/041181/public/sites/www.maccusfoto.nl/zenphoto/zp-core/template-functions.php on line 1681
  • Well, this code kind of messes with the normal Zenphoto flow of things. For the breadcrumbs, I would guess it would work if you print the breadcrumbs before invoking this code. For the search error, you will have to put some code in to be sure that the search returned something (the $zp_albums) is not empty.)
  • Maccus Member
    Well I solved the albumtitle issue, but my PHP coding abilities are too limited to fix the search error. Does anyone else have a solution maybe ? My search.php:

    `

    <?php if (function_exists('printAdminToolbox')) printAdminToolbox(); ?>





    Stock foto database. Voer een zoekterm in...

    <?php if (getOption('Allow_search')) { printSearchForm(); } ?>



    <?php $_zp_albums = $_zp_current_search->getAlbums(0);
    foreach ($_zp_albums as $key=>$albumname); {
    $album = new Album($_zp_gallery, $albumname);
    if ($album->getNumImages() == 0) {unset($_zp_albums[$key]);}
    } ?>

    <?php while (next_album()): $c++; ?>
    <?php if (getNumImages() !=0) : ;?>



    <?php endif; ?>
    <?php endwhile; ?>







    <?php while (next_image(false, $firstPageImages)): $c++;?>




    <?php printImageThumb(getBareImageTitle()); ?>
    <?php echo getBareImageTitle(); ?>
    <?php echo printImageDesc(true); ?>




    <?php endwhile; ?>




    <?php if ($c == 0) {echo "".gettext("Sorry, no image matches. Try refining your search.")."
    ";}

    printPageListWithNav("« ".gettext("prev"),gettext("next")." »"); ?>




    `
    http://maccusfoto.nl/zenphoto/page/search/fields255/roma

    http://maccusfoto.nl/zenphoto/page/search
  • The error is comming from your call on getNumImages() in the album loop. Since the other code insures you are not looking at albums with no images, maybe you can just eliminate that test.
  • Maccus Member
    Eliminating that test does not change anything, still the same errors on an empty search or a search with a searchterm that shows no result. And when I do a normal search, the empty subalbums are back an pagination is gone. All images on the same page...
  • Sorry, then. I am out of ideas.
  • Maccus Member
    OK, thanx anyway for the support.
Sign In or Register to comment.