Thread tagged as: Problem, Configuration

perch_content_custom showing content from multiple different pages

I have 7 different pages with the same named region 'Stock listings'.

On each of these pages, each new item I add goes to the top of the page.

I have another page where I show all items from each of the different pages using the following code:

<?php perch_content_custom('Stock listings', array(
    'page'=>array('/our-stock/tractors.php', '/our-stock/vintage-and-classic-machinery.php', '/our-stock/cultivation.php', '/our-stock/trailers.php', '/our-stock/grass-equipment.php', '/our-stock/wheels-and-tyres.php', '/our-stock/other-equipment.php'),

I expected that when adding an item to any of the pages, it would show the latest item at the top of this page like they do on each individual page but they get added in a strange order.

Jack Linwood

Jack Linwood 0 points

  • 7 years ago

Any update?

If I was doing this, I would sort on a specific field i.e with something like this

'sort' => 'id-of-your-field',
            'sort-order' => 'DESC',

Thanks Clive, but I don't have a field ID that would create an order that would make sense.

I just need the latest item I post on any page to go to the top like it does on all the individual pages.

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Clive is correct, you need to add a field to sort by to use sort-order. Otherwise - what are you asking to be sorted?

If you don't have such a field that makes sense you will need to add one if you want to include multiple regions. Adding a date would be a good approach.

Okay, so in order to get what I need I would need to add a time and date field.

Can I sort them by the newest item this way?

Rachel Andrew

Rachel Andrew 394 points
Perch Support

Then you should be able to sort them by date. So most recent date first.

That doesn't work if you are uploading multiple items in one day.

Does it work by time at all?

Or is there not another way I can get them to go to the top? They are doing it on individual pages but just a very random order when pulling in from multiple pages.

You would template something like this

<perch:content id="dateTime" type="date" label="Date & Time" time="true" format="%A, %e %B %Y %H:%M" suppress="true" required="true" />

Then filter like this:

perch_content_custom('YOUR REGION', array(
   'template'   => 'template.html',
   'sort' => 'dateTime',
   'sort-order' => 'DESC'

Cracked it Dexter, thanks a lot mate.