Forum

Thread tagged as: Question

Can you sort custom content regions on a page manually?

I have a question regarding sorting. I pull through data from some other pages onto a general news page using this snippet...

<?php
     perch_content_custom('News', array(
       'page'=>'/*',
      'template'=>'news.html',
    )); 
?>

I'd like the customer to be able to sort how they appear listed on this page manually. Reordering the pages in the backend using 'reorder pages' doesn't change the order in which they appear listed on the page. What could I add to enable this?

John Robinson

John Robinson 0 points

  • 5 years ago
Drew McLellan

Drew McLellan 2638 points
Perch Support

You can't, and it points to perhaps an improvement that could be make in how your site is structured. What's the reason for multiple independent regions of news? If they are all to be displayed sometimes together as well as apart, why are they not one single collection of news items?

This main news page shows an excerpt of each news story with a prompt to read more. Clicking through to the individual story on its own page shows the full story with more imagery and lightboxes etc.

For the main news page what options could be available for sorting using perch_content_custom?

cheers

Drew McLellan

Drew McLellan 2638 points
Perch Support

What's the reason for multiple independent regions of news?

Its the best way I could find to make this section work, and it works apart from having difficulty sorting.

if it helps this is the general news page I mention.

https://designlinearchitectural.co.uk/news.php

With the snippet I mentioned in the original post i'm not sure how this page is sorting (date page created?) so i'm appealing for guidance as to sort options?

Drew McLellan

Drew McLellan 2638 points
Perch Support

You should be able to sort by any of the common fields. You cannot sort by page.

Could you point me to any documentation about the common sorts please?

I'm looking here..

https://docs.grabaperch.com/docs/content/perch-content-custom/

I see how sort is used in the example

        'sort'=>'date',
        'sort-order'=>'DESC',

but not sure what else i can do eg sort alphabetically

Drew McLellan

Drew McLellan 2638 points
Perch Support

That's correct. If you want to sort by a field alphabetically:

        'sort'=>'id_of_field_to_sort_by',
        'sort-order'=>'ASC',

cheers