how to display last page of entities?

I want to know is it possible to display last page of entities ? in default pagination, elgg_list_entities will display page 1 , and we must click "1,2,... Next' button to go to other page,
for some reason i want to display last page

I've used

header('location: ...');

to redirect to last page, but i wonder if there is simple way to do this :)

  • I assume you want the URL to the last page.

    Given $options from a query: add ["count" => true] to $options and run the query to get $count.

    $per_page = elgg_get_config('default_limit');
    $num_pages = ceil($count / $per_page);
    if ($num_pages > 1) {
      $offset = ($num_pages - 1) * $per_page;
      $url = elgg_http_add_url_query_elements($url, ['offset' => $offset])
    }
    
    forward($url);
    
    
  • If you don't want to display pagination, do the same operations to get $offset, then add ['offset' => $offset] and ['pagination' => false] to the query $options.

  • @Steve maybe he wants the order by ascending? Oldest post goes to the top of the first page instead of default?