Skip to content

Commit

Permalink
Added ellipsis controll
Browse files Browse the repository at this point in the history
  • Loading branch information
mt-gareth committed Apr 6, 2020
1 parent f07c577 commit 2f39e8b
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/WP_Ajax.php
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ protected function getPostsAndPages()
return [ $posts, $current_page, $max_pages ];
}

public static function arrayOfPages( $current_page, $max_pages, $pages_to_show = 9 )
public static function arrayOfPages( $current_page, $max_pages, $pages_to_show = 9, $ellipsis_char = '...' )
{
if ( !( $pages_to_show % 2 ) ) $pages_to_show--; // if $pages_to_show not odd subtract 1 to make it so
$pages_on_either_side = ( $pages_to_show - 1 ) / 2 - 2;
Expand All @@ -96,8 +96,8 @@ public static function arrayOfPages( $current_page, $max_pages, $pages_to_show =
if ( $current_page > $max_pages - $page_to_show_all && $page > $max_pages - $page_to_show_all - $pages_on_either_side ) return true;//if we are within $pages_to_show - 2 of the end just show the last $pages_to_show - 2
return false;
} ) );
if ( $page_array[ 1 ] !== 2 ) array_splice( $page_array, 1, 0, [ 'E' ] );
if ( $page_array[ count( $page_array ) - 2 ] !== $max_pages - 1 ) array_splice( $page_array, count( $page_array ) - 1, 0, [ 'E' ] );
if ( $page_array[ 1 ] !== 2 ) array_splice( $page_array, 1, 0, [ $ellipsis_char ] );
if ( $page_array[ count( $page_array ) - 2 ] !== $max_pages - 1 ) array_splice( $page_array, count( $page_array ) - 1, 0, [ $ellipsis_char ] );
return $page_array;
}
}

0 comments on commit 2f39e8b

Please sign in to comment.