Stumped: sorting page_list results by a custom attribute, how to control the results count in 5.7?
Permalink
I am using a custom page_list template to sort and filter page results by a custom attribute. In 5.6 I could control the number of page results to display with $pl->get();. I could pass an integer for the number of page results I wanted to display, in 5.7 this doesn't seem to work.
Any assistance would be greatly appreciated.
Example:
Any assistance would be greatly appreciated.
Example:
<?php $pl = new PageList(); $pl->filterByCollectionTypeHandle('event_entry'); $datetime = strtotime('-1 day'); $mysqldate = date("Y-m-d H:i:s", $datetime); $pl->filterbyAttribute('event_date_time', $mysqldate, '>'); $pl->sortBy('ak_event_date_time', 'asc'); // in 5.6 this would control the number of page results to display // it would get 5 pages that met the filter and sort // $pl->get(5); $pages = $pl->get(); ?>
Just tried, doesn't work for me either
The PageList get() function was deprecated. The new way I believe is to use the pagination object (see code snippet) but I'm still not sure you can only get X pages of results.
I'm actually not sure why you would only want to get 5 pages here? If it's going to be paginated anyway why limit this here?
$pagination = $pl->getPagination(); $pages = $pagination->getCurrentPageResults();
I'm actually not sure why you would only want to get 5 pages here? If it's going to be paginated anyway why limit this here?
"The PageList get() function was deprecated. The new way I believe is to use the pagination object (see code snippet) but I'm still not sure you can only get X pages of results."
Sorry, to be more specific, I am looking to limit the number of results not pages of results.
"$pagination = $pl->getPagination();
$pages = $pagination->getCurrentPageResults();"
I will give this a shot, thank you.
"I'm actually not sure why you would only want to get 5 pages here? If it's going to be paginated anyway why limit this here?"
I often use the page_list without pagination. For example, I might have a home page section that lists the next upcoming 5 events (just the 5, without pagination).
Sorry, to be more specific, I am looking to limit the number of results not pages of results.
"$pagination = $pl->getPagination();
$pages = $pagination->getCurrentPageResults();"
I will give this a shot, thank you.
"I'm actually not sure why you would only want to get 5 pages here? If it's going to be paginated anyway why limit this here?"
I often use the page_list without pagination. For example, I might have a home page section that lists the next upcoming 5 events (just the 5, without pagination).
O gotcha,
I think that you could maybe just set the "MaxPerPage" property, then just pull back the first page yes?
(stab in the dark below)
Edit: For clarity I simply misunderstood since by "Pages" you were referring to the number of objects in the list, I was stuck on pagination.
I think that you could maybe just set the "MaxPerPage" property, then just pull back the first page yes?
(stab in the dark below)
$pagination = $pl->getPagination(); $pagination->setMaxPerPage(5); $pages = $pagination->getCurrentPageResults();
Edit: For clarity I simply misunderstood since by "Pages" you were referring to the number of objects in the list, I was stuck on pagination.
$pagination = $pl->getPagination(); $pagination->setMaxPerPage(5); $pages = $pagination->getCurrentPageResults();
That worked, thank you very much.