Forked from JiveDig/facetwp-pagination-genesis-markup.php
Created
July 27, 2018 09:03
-
-
Save deckerweb/ceb5b915a6a1cfd3b484995a85f5f2a4 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"]
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
<?php | |
/** | |
* Style pagination to look like Genesis. | |
* | |
* @version 1.0.0 | |
* | |
* @author Mike Hemberger @JiveDig | |
* | |
* @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 ) . '">« 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">…</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">…</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 »</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