Skip to content

Instantly share code, notes, and snippets.

@Jeradin
Last active January 27, 2017 18:28
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save Jeradin/b01b3b68ff7b69d957d848fa519a5d66 to your computer and use it in GitHub Desktop.
Save Jeradin/b01b3b68ff7b69d957d848fa519a5d66 to your computer and use it in GitHub Desktop.
/**
* 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;
}
@zackkatz
Copy link

zackkatz commented May 9, 2016

Thanks @Jeradin - this is a great start!

@usefulartservices
Copy link

Thank you @Jeradin!

@usefulartservices
Copy link

Hi @Jeradin, this is catching all entries in my form, including trashed entries, and entries that have not been approved (this is relevant if a view is set to only show approved entries). Any ideas ?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment