Last active
February 26, 2026 01:44
-
-
Save Jeradin/b01b3b68ff7b69d957d848fa519a5d66 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
| /** | |
| * Get single entry pagination links | |
| * to use: call anagram_entry_pagintion(); | |
| * | |
| */ | |
| function anagram_entry_pagintion() { | |
| global $gravityview_view; | |
| $criteria['paging'] = array( | |
| 'offset' => 0, | |
| 'page_size' => 200 | |
| ); | |
| $criteria['sorting'] = array( | |
| 'key' => $gravityview_view->atts['sort_field'], | |
| 'direction' => $gravityview_view->atts['sort_direction'] | |
| ); | |
| //Using this below to get all entry IDs, I know there is a direct function for that, but wanted to preserve the Views sort order. | |
| $entry_ids = wp_list_pluck( gravityview_get_entries( $gravityview_view->form_id , $criteria, $sorting ), 'id' ); | |
| $total_count = count($entry_ids); | |
| $current_entry = get_query_var( 'entry' ); | |
| $position = array_search($current_entry, $entry_ids); | |
| $prev_pos = ! rgblank( $position ) && $position > 0 ? $position - 1 : false; | |
| $next_pos = ! rgblank( $position ) && $position < $total_count - 1 ? $position + 1 : false; | |
| $post_id = $gravityview_view->getPostId(); | |
| $query_arg_name = GravityView_Post_Types::get_entry_var_name(); | |
| $output = '<ul class="list-inline">'; | |
| $output .= '<li class="gf_entry_count">'; | |
| $output .= '<span>entry <strong>'. ($position + 1) .'</strong> of <strong>'. $total_count .'</strong></span>'; | |
| $output .= '</li>'; | |
| $output .= '<li class="gf_entry_prev gv_pagination_links">'; | |
| $output .= '<a href="' . GravityView_API::entry_link( $entry_ids[$prev_pos] ) . '" class="' . ($prev_pos !== false ? ' ' : ' gf_entry_disabled') . '" title="Previous Entry"><i class="fa-lg fa fa-arrow-circle-o-left"></i></a></li>'; | |
| $output .= '</li>'; | |
| $output .= '<li class="gf_entry_next gv_pagination_links">'; | |
| $output .= '<a href="' . GravityView_API::entry_link( $entry_ids[$next_pos] ) . '" class="' . ($next_pos !== false ? ' ' : ' gf_entry_disabled') . '" title="Next Entry"><i class="fa-lg fa fa-arrow-circle-o-right"></i></a></li>'; | |
| $output .= '</li>'; | |
| $output .= '</ul>'; | |
| return $output; | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Updated snippet that works with GravityView 2+:
gravityview()->requestAPI instead of the deprecatedglobal $gravityview_viewNote: if you have more than 500 entries in a View, increase the page_size value.