Are there any best practices for displaying a limited number of page links around the current page?

When displaying a limited number of page links around the current page, it is important to provide users with easy navigation while keeping the interface clean and uncluttered. One common approach is to display a set number of page links before and after the current page, with ellipses (...) to indicate additional pages. This allows users to easily navigate to nearby pages without overwhelming them with too many options.

<?php
$current_page = 5;
$total_pages = 10;
$links_before_after = 2;

for ($i = max(1, $current_page - $links_before_after); $i <= min($current_page + $links_before_after, $total_pages); $i++) {
    echo "<a href='page.php?page=$i'>$i</a> ";
    if ($i == $current_page) {
        echo "(current) ";
    }
}

if ($current_page - $links_before_after > 1) {
    echo "... ";
}

if ($current_page + $links_before_after < $total_pages) {
    echo "... ";
}

?>