Forum
sort-order not working
I'm trying to get a list of images from a repeater in random order using perch_content_custom but changing the sort-order or count does nothing.
perch_content_custom('Slideshow', array(
'page'=>'/index.php',
'template'=>'slides.html',
'sort-order'=>'RAND',
'count'=>3
));
Here's the slides.html template:
<perch:repeater id="slides" label="Slider images">
<img src="<perch:content id="image" type="image" width="2200" height="1100" crop="true" quality="30" sharpen="2" />" alt="<perch:content id="alt" type="text" />" />
</perch:repeater>
All 7 slides are output in descending order, not 3. I tried adding 'sort'=>'image' and 'sort'=>'alt' to the parameter list but nothing is output at all when I add this in. Any ideas why this could be?
Diagnostics:
Perch: 2.8.24, PHP: 5.6.10, MySQL: mysqlnd 5.0.11-dev - 20120503 - $Id: 3c688b6bbc30d36af3ac34fdd4b7b5b787fe5555 $, with PDO
Server OS: Darwin, apache2handler
Installed apps: content (2.8.24), assets (2.8.24), categories (2.8.24), perch_blog (5.0), perch_forms (1.8.3)
App runtimes: <?php $apps_list = array( 'content', 'categories', 'perch_blog', 'perch_forms', );
PERCH_LOGINPATH: /perch
PERCH_PATH: /Users/adam/Sites/burtownhouse.ie/site/perch
PERCH_CORE: /Users/adam/Sites/burtownhouse.ie/site/perch/core
PERCH_RESFILEPATH: /Users/adam/Sites/burtownhouse.ie/site/perch/resources
Image manipulation: GD
PHP limits: Max upload 32M, Max POST 32M, Memory: 128M, Total max file upload: 32M
F1: dc1fef2ad0fcd9f943c02ebb43d85dbc
Resource folder writeable: Yes
HTTP_HOST: burtownhouse.dev
DOCUMENT_ROOT: /Users/adam/Sites/burtownhouse.ie/site
REQUEST_URI: /perch/core/settings/diagnostics/
SCRIPT_NAME: /perch/core/settings/diagnostics/index.php
You need to set
sort
forsort-order
to have any context. Could you try that?That's what I assumed, though when I try that nothing is output at all:
Sorting on image will sort on its file path - is that what you're expecting?
If not, what are you expecting?
I'd like them output in random order so it shouldn't matter what id I sort them on - there are only 2 ids to choose from (image and alt), but when I try either (
'sort'=>'image'
or'sort'=>'alt'
), no images are output!The last code excerpt was meant to be RAND, not DESC:
If you remove the sorting, do the images show?
Yes, all 7 images show when
'sort'=>'image'
is removed.'count'=>3
doesn't appear to limit the number either.If you turn on debug for the page and add the sorting back in, what does it output?
Thanks Drew, here's the debug output:
slides.php:
slides.html template:
This is the main slideshow.html template assigned to the 'Slideshow' content region in index.php
Ah, so your region contains only 1 item, and that 1 item has a repeater with all your images in?
Yep that's right. Is that wrong?
No wrong, but it's not going to do what you want in this case. Repeaters can't be sorted or filtered.
In this case it would be better to set the region to allow multiple items (in the region options) and then add one image per item, without a repeater.
Thanks Drew, that's it. Sorry I didn't cop that sooner!