How to exclude an album from search function ?

Hello,

I use the same Zenphoto cms for pictures (PC,tablets, smartphones) and VR headsets.
Using a VR headset ? you are redirected in the VR album, with all sub-albums available.
You cannot enter the VR section if you use a Pc/tablet (smartphones are OK in VR with a cheap headset)

Can I alter the search function so that the VR album + sub-albums are excluded from results ?
(no search page in VR section)

Thank you in advance !

Tags:

Comments

  • acrylian Administrator, Developer
    edited November 2025

    While the searchEngine class has a property for that it for some reason cannot be set directly being protected.

    Thte searchform function has only a parameter to set where to search but not to exclude.

    I had to look myself: A small not so elegant workaround seesm to work by re-creating a new searchEngine object. So on your search.php try this right before all the search code:

    //search takes parameters by POST/GET queries on object creation
    $_REQUEST['excludealbums'] = 'youralbumname'; // comma separated list of album names to exclude
    $_zp_current_search = new SearchEngine();
    // normal search.php code here.
    
  • Thank you so much, it works perfectly.
    My problem is solved.

    That question and your response could help some other Zenphoto users !

  • acrylian Administrator, Developer

    I probably just found the more elegant way without neeeding to overwrite the existing search object:

     $paramstr = 'excludealbums=orientation'; 
     $_zp_current_search->setSearchParams($paramstr);
    

    I was not sure if setting that would clear any other search params submitted already but seems to work for me, too.

  • ctdlg Member

    A new question about search and Zenphoto :
    can we clone the search.php file so that we can perform a search on my album that is exluded from standard search ?
    If yes, I would add a search button on the page of that album ( i would also exclude all other albums )
    I tried without success, probably beacause search.php uses template functions.

  • acrylian Administrator, Developer

    can we clone the search.php file so that we can perform a search on my album that is exluded from standard search ?

    If yes, I would add a search button on

    No, as that is what serves the results. All theme files "use" template-functions as that is what "runs" the theme ;-)

    You of course have to use the function for the search button. And that has a objectlist parameter to limit search:
    https://docs.zenphoto.org/1.6.x/namespaces/default.html#function_printSearchForm

  • acrylian Administrator, Developer

    The doc is not clear about $object_list I think. You use it this way:

     $object_list =  array("albums"=>array('albumname', 'another-albumname', ...))
    

    You could run into problems if that album is excluded on the search.php page as well. So you possibly need to the check parameters you recieve there to override the exclusion on that occasion.

  • ctdlg Member
    edited January 23

    I do not fully understand what I can do.
    My website is divided in 2 main parts :
    Pc, smarphones and pads.
    Vr headsets.

    Right now, We can search within the PC section.
    The VR album is excluded from this search thanks to your advice.

    To have a search within the VR section that excludes the PC section, what do I need to change or add ?
    See https://clatique.fr

  • acrylian Administrator, Developer
    edited January 23

    You need to add a check on what album (and/or subalbum) you are and add the search form to include or exclude that album.

    Since the search form passes the query to the search page you need to check there what you request. if you there hardcode an exclusion for an album you need to override that here if you actually want to search within that album.

    Sorry this is a bit more advanced stuff.

  • acrylian Administrator, Developer
    edited January 23

    If you use this check on your search.php page:

    $paramstr = 'excludealbums=albumname_to_exclude'; 
    $_zp_current_search->setSearchParams($paramstr);
    

    Right before you need to check if you request that album you excluded.

    if(!in_array('albumname_to_exclude', $_zp_current_search->album_list)) {
       $paramstr = 'excludealbums=orientation'; 
       $_zp_current_search->setSearchParams($paramstr);
    }
    

    This is just off hand. I have not tried this or checked the structure of the $_zp_current_search->album_listarray but this should give you an idea.

  • ctdlg Member

    Sorry for late reply !

    if(!in_array('albumname_to_exclude', $_zp_current_search->album_list)) {
    $paramstr = 'excludealbums=orientation';
    $_zp_current_search->setSearchParams($paramstr);
    }
    gives me a blank page.

    I understand the principle, but even after correcting the code, the album I'm searching for isn't being taken into account. It's as if the parameter isn't being retrieved on the search.php page.

  • acrylian Administrator, Developer

    As mentioned the code above was quickly off hand and not tested as I had never to try this. Best you review the log to see what the error is.

    Did you actually also modify the search form function paramater on the specific album that is otherwise exclude? If not it is of course not passed to check at all, too.

    I will see if I get the chance to try myself the next days.

Sign In or Register to comment.