[1.4.5] Search sort order & pagelist navigation

Hi all,

I changed the sort order on the searchpage by doing this:

`<?php while (next_image(false, NULL, 'date', 'desc')): ?>`

This works...latest pictures on first page, first pictures on last page.

On the first page with the latest pictures the printPageListWithNav shows the previous link instead of the next link.

`printPageListWithNav( gettext('« Prev'),gettext('Next »'),false,'true','pagelist','',false,'7' );`

Is there a way to change this?

TIA

Comments

  • Right off hand I do not see a way. What is needed is to set the search sort type/direction at the beginning of the script so that it is used by anyone fetching the images (e.g. next/prev).

    This would be a reasonable new feature. Maybe create an issue requesting it.
  • I did think of a way to do this with the current software. A bit obscure, but I believe it will work.

    You will need to create your own search object that extends `searchEngine`. Your object constructor should set the internal image and album sort variables to the values you want. Then your script would need to instantiate your object and store that into the `$_zp_current_search` variable.

    Thought of a second thing to try. Searches are cached, so what you need to do is call a dummy `next_image` before anything else to get the list in the correct order. All else (presuming they do not pass sort parameters) will just use that cached list.
  • Hi sbillard,

    I saw on github that you worked out this feature. Today I checked my website with `<?php while (next_image(false, NULL, 'date', 'desc')): ?>` again and it works....but not 100%.

    With the code I get the latest pictures on the first page and the first pictures on the last page. The code with the printPageListWithNav in my first post also worked.

    After a search input I get the search output, say 16 thumbnails on 1 page. When I select 1 thumbnail (this goes to a 600x400px image) and press next for the next 600x400px image the order is not as in the thumbnail search output.

    Am I missing something here in the code....

    Extra links:

    https://github.com/zenphoto/zenphoto/issues/458
    https://github.com/zenphoto/zenphoto/issues/459

    I really appreciate all your work on zenphoto.org.

    TIA

    Michel
  • Probably you are missing something. If all you have is the next_image loop it does not globally set the order (as mentioned in issue #459.)

    You need to set the direction globally with the search engine method `setSortType($type,$what)`. Ideally this should be done as one of the first things in your script to insure that no code has fetched search results before you have set the direction.
  • Hi sbillard,

    I read the github issue#459, but I don't get it.

    Can you give me a example how to implant this into a search.php?

    TIA
  • acrylian Administrator, Developer
    Place the function sbillard referred to at the beginning of your theme's search.php file and set its parameters as wished.
  • Hi

    The function does not work like this:
    `<?php setSortType('desc','image');?>`

    I'm confused right now :-)

    TIA
  • acrylian Administrator, Developer
    No, of course not since the function is a search method as mentioned above. You need to use it with the current search object `$_zp_current_search->setSortType()`.
  • Hi,

    Thnx for your explanation, at the beginning of my search.php i have this now:

    `
    <?php
    zp_apply_filter('theme_body_open');
    $total = getNumImages() + getNumAlbums();
    if (!$total) {
    $_zp_current_search->setSortType('desc','image');
    }
    ?>
    `
    Still a no-go.

    TIA
  • acrylian Administrator, Developer
    The first parameter is not the direction but what to sort like id or date. For the direction there is another method.
  • You selected sorting by the `desc` field, I think you want to sort by the `date` field.

    `$_zp_current_search->setSortType('date','image');`

    As well, you have executed code that does the search (the bit about the number of images) before setting this direction, so things will already have been cached.
Sign In or Register to comment.