Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* Filter search criteria */
- add_filter( 'gravityview_search_criteria', function( $criteria ) {
- if( isset($_GET['custom_count']) ) {
- $criteria['paging']['page_size'] = $_GET['custom_count'];
- };
- return $criteria;
- } );
- /*
- * Create Shortcode
- * Usage: [gv_custom_page_dropdown]
- */
- add_shortcode('gv_custom_page_dropdown', 'gv_custom_page_dropdown');
- function gv_custom_page_dropdown($atts) {
- global $gravityview_view;
- $pagination_counts = $gravityview_view->getPaginationCounts();
- $total = $pagination_counts['total'];
- $last = $pagination_counts['last'];
- $minimum_posts_per_page = isset($atts['minimum-posts-per-page']) ? $atts['minimum-posts-per-page'] : 25;
- if($total <= $minimum_posts_per_page) {
- return;
- }
- $current_posts_per_page = isset($_GET['custom_count']) ? intval($_GET['custom_count']) : $minimum_posts_per_page;
- // Begin posts_per_page dropdown
- $customDropdown ='<form method="get" class="form-inline">';
- $customDropdown .='<select class="btn btn-default" name="custom_count">';
- // Create all custom options below total
- $x = $minimum_posts_per_page;
- while($x < $total) {
- $customDropdown .= "<option value='$x'";
- if($x == $current_posts_per_page) {
- $customDropdown .= ' selected';
- }
- $customDropdown .= ">$x</option>";
- $x *= 2;
- }
- // Create final option
- $customDropdown .= "<option value='$x'";
- if($x == $current_posts_per_page) {
- $customDropdown .= ' selected';
- }
- $customDropdown .= ">$x</option>";
- $customDropdown .= '</select>';
- $customDropdown .='<input type="submit" class="btn btn-xs btn-primary" value="Update" />';
- $customDropdown .='</form>';
- return $customDropdown;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement