Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Back End Pagination dots …. between numbers Re: Pagination dots …. between numbers

#72942
willB
Member

I assume you mean for page links as in a archive of blog posts? or just an array of numbers? Either way the concept would be similar, you would need to test where in the array you’re outputting you are, and based on the results output the ellipsis.



$numbers = array(1,2,3,4,5,6,7,8,9,10,11,12);
$output = '';
$counter = 1;
foreach ($numbers as $number){

if($counter == 4){
$output .= ' ...';
}elseif($counter < 4 || $counter > (count($numbers) -3)){
$output .= ' ' . $number;
}
$counter++;
}

That should give you the results in your example, if you were to do it with pages and links you would replace the simple array with an array of the pages you need to link to and probably output the counter wrapped by an anchor tag with the link from the array, I hope this was helpful.