Created
July 4, 2019 11:16
-
-
Save DarioBF/785de47525b0d2ca4a2baef9249a7655 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* FacetWP Pagination | |
* You should print it with `echo facetwp_display( 'pager' );` if you prefer that to shortcode method | |
*/ | |
function bf_custom_paginator_facetwp( $output, $params ) { | |
$output = ''; | |
$page = (int) $params['page']; | |
$total_pages = (int) $params['total_pages']; | |
// Only show pagination when > 1 page | |
if ( 1 < $total_pages ) { | |
if ( 1 < $page ) { | |
$output .= '<a class="facetwp-page" data-page="' . ( $page - 1 ) . '">« Anteriores</a>'; | |
} | |
if ( 3 < $page ) { | |
$output .= '<a class="facetwp-page first-page" data-page="1">1</a>'; | |
$output .= ' <span class="dots">…</span> '; | |
} | |
for ( $i = 2; $i > 0; $i-- ) { | |
if ( 0 < ( $page - $i ) ) { | |
$output .= '<a class="facetwp-page" data-page="' . ($page - $i) . '">' . ($page - $i) . '</a>'; | |
} | |
} | |
// Current page | |
$output .= '<a class="facetwp-page active" data-page="' . $page . '">' . $page . '</a>'; | |
for ( $i = 1; $i <= 2; $i++ ) { | |
if ( $total_pages >= ( $page + $i ) ) { | |
$output .= '<a class="facetwp-page" data-page="' . ($page + $i) . '">' . ($page + $i) . '</a>'; | |
} | |
} | |
if ( $total_pages > ( $page + 2 ) ) { | |
$output .= ' <span class="dots">…</span> '; | |
$output .= '<a class="facetwp-page last-page" data-page="' . $total_pages . '">' . $total_pages . '</a>'; | |
} | |
if ( $page < $total_pages ) { | |
$output .= '<a class="facetwp-page" data-page="' . ( $page + 1 ) . '">Siguientes »</a>'; | |
} | |
} | |
return $output; | |
} | |
add_filter( 'facetwp_pager_html', 'bf_custom_paginator_facetwp', 10, 2 ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment