Skip to content

Instantly share code, notes, and snippets.

@JiveDig
Last active September 24, 2021 18:54
Show Gist options
  • Star 6 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save JiveDig/b9810ba4c322d7757993159ed9ccb61f to your computer and use it in GitHub Desktop.
Save JiveDig/b9810ba4c322d7757993159ed9ccb61f to your computer and use it in GitHub Desktop.
Adjust FacetWP's pager html to match Genesis markup. This allows it to inherit the Genesis theme styles. Used with [facetwp pager="true"]
<?php
/**
* Style pagination to look like Genesis.
*
* @version 1.0.0
*
* @author Mike Hemberger @JiveDig
*
* @link https://gist.github.com/JiveDig/b9810ba4c322d7757993159ed9ccb61f
* @link https://halfelf.org/2017/facetwp-genesis-pagination/
* @link https://gist.github.com/mgibbs189/69176ef41fa4e26d1419
*/
add_filter( 'facetwp_pager_html', 'prefix_genesis_facetwp_pager', 10, 2 );
function prefix_genesis_facetwp_pager( $output, $params ) {
$output = '<div class="archive-pagination pagination"><ul>';
$page = (int) $params['page'];
$total_pages = (int) $params['total_pages'];
// Only show pagination when > 1 page.
if ( 1 < $total_pages ) {
if ( 1 < $page ) {
$output .= '<li><a class="facetwp-page" data-page="' . ( $page - 1 ) . '">&laquo; Previous Page</a></li>';
}
if ( 3 < $page ) {
$output .= '<li><a class="facetwp-page first-page" data-page="1"><span class="screen-reader-text">Page </span>1</a></li>';
$output .= '<li class="pagination-omission">&hellip;</li>';
}
for ( $i = 2; $i > 0; $i-- ) {
if ( 0 < ( $page - $i ) ) {
$output .= '<li><a class="facetwp-page" data-page="' . ($page - $i) . '"><span class="screen-reader-text">Page </span>' . ($page - $i) . '</a></li>';
}
}
// Current page.
$output .= '<li class="active"><a class="facetwp-page" aria-label="Current page" data-page="' . $page . '"><span class="screen-reader-text">Page </span>' . $page . '</a></li>';
for ( $i = 1; $i <= 2; $i++ ) {
if ( $total_pages >= ( $page + $i ) ) {
$output .= '<li><a class="facetwp-page" data-page="' . ($page + $i) . '"><span class="screen-reader-text">Page </span>' . ($page + $i) . '</a></li>';
}
}
if ( $total_pages > ( $page + 2 ) ) {
$output .= '<li class="pagination-omission">&hellip;</li>';
$output .= '<li><a class="facetwp-page last-page" data-page="' . $total_pages . '"><span class="screen-reader-text">Page </span>' . $total_pages . '</a></li>';
}
if ( $page < $total_pages ) {
$output .= '<li><a class="facetwp-page" data-page="' . ( $page + 1 ) . '">Next Page &raquo;</a></li>';
}
}
$output .= '</ul></div>';
return $output;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment