Forum
sorting pages from newest to oldest
I have a news type section - it's using Pages rather than the Blog app but i'm trying to sort by showing the most recently created/edited page first, but i can't get this to work. Each fresh page appears in a grid on a 'home' page, this is the code that pulls it through..
<?php perch_content_custom(array('product'), array(
'page'=>PerchUtil:: strip_file_name (PerchSystem::get_page()).'*',
'template'=>'lift-list.html',
'count'=>'12',
'paginate'=>'true',
'sort'=>'heading',
'sort-order'=>'DESC',
)); ?>
The pagination works and the code sorts alphabetically according to the text in heading. How can i sort by date? i don't really want the person to have to enter a date, would be good if it recognised when the page was created
Thanks
Which field are you using for the date?
Hi Drew,
Thanks for the reply.
I have all content regions grouped ie you click once and see a number of regions which are a mixture of image uploads and text areas. Heading is one which is a single line of text field.
This may be the issue, i don't have anything in here with a date, do i create a new field?
You need to add whatever field you want to sort by.
Would that be adding a field with a numeric input which has to be filled in with a number to sort by, or can i use something that generates the date automatically and references the newest page?
I want to sort it by the newest page ideally, with no extra inputs required making it easy for the client . Alternatively could the reorder pages feature be used?
Cheers
You can use the navigation functions to get the pages in order.
If you want to get the content in a specific order, you need to have a field to order it by.
Thanks i'm going down the route of using navigation but pulling through an image as well.
I've tried to adapt the above item.html template in the navigation folder to iclude an image with code that worked before
this suggests this is possible but it doesn't seem to work..
https://docs.grabaperch.com/docs/pages/page-attributes/use-in-navigation/
any advice is much appreciated, thanks
What does it output? What options are you setting?
The immediate thing that stands out is the use of a
perch:content
tag.An empty image tag is output... img src=""
Have you fixed the tag issue?
Hi Drew.
No, as i'm not sure what else to try. I read the perch manual on navigation..
"Just use the exact <perch:pages /> tags that you use in your Page Attribute templates in your Navigation template, any content added to that page will then be available for use."
and tried the snippet that worked outside of navigation.
Is <perch:content definately wrong? changing perch:content to <perch:pages doesn't work.
I haven't used <perch:pages anywhere else - should <perch:pages be used in the navigation template AND have something to match up with?
You can't use
<perch:content />
tags in a navigation template.Thanks for confirming, could you point me to the way to pull an image through?
What is the current state? Are you adding the images through page attributes? Can you see them in the template through
<perch:showall />
?