Forum

Thread tagged as: Problem, Gallery

Gallery Sort Desc

Hi all,

I am not entirely sure what I am doing wrong but I don't seem to be able to get the gallery to sort descending.

I am giving the image a number using perch_item_index and telling it to sort using that id? Can anyone see what I am doing wrong?

Template:

<li class="col-lg-2 col-md-2 col-sm-3 col-xs-4"><a data-lightbox="gallery" href='<perch:gallery id="main" />'>
    <img id='<perch:gallery id="perch_item_index" type="hidden" />' data-lightbox="gallery" class="img-responsive" src='<perch:gallery id="small" />' width='<perch:gallery id="small-w" />' height='<perch:gallery id="small-h" />' alt='<perch:gallery id="imageAlt" />' />
</a></li>

Page:

$opts = array(
                    'count'=>24,
                    'paginate'=>true,
                    'sort'=>'perch_item_index',
                    'sort-order'=>'DESC',
                );
                perch_gallery_images($opts);

Any help would be appreciated!

Thanks, Martin

Martin Murphy

Martin Murphy 0 points

  • 6 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't sort on perch_item_index - that is the order the items are output by the template engine. It always starts at 1 no matter which way the content is sorted. You need to sort by a field in the data.

Hmm well this is what I thought but just adding 'sort-order'=>'DESC' doesn't work?

Whats the best way to just display newest items first in the gallery as there aren't the options to do that within the perch admin.

Thanks for the response Drew.

Oh sorry... Found it.

The images already come with an id of imageOrder so sorted by that and it works,

Thanks anyway!

Martin