Adding pagination to the Single Entry page

When viewing a single entry in GravityView, you may want to navigate between entries without going back to the main list. Single entry pagination adds "Previous" and "Next" links along with an "Entry X of Y" counter, allowing you to browse through entries one at a time.

This is useful for administrators or staff who need to review entries in sequence — for example, reviewing job applications, grading submissions, or auditing form responses.

Note: Single entry pagination is built in to the lightbox view. Arrows on either side of the lightbox allow you to navigate between entries.

How it works

The pagination snippet adds navigation controls to the bottom of the Single Entry view. These controls include:

  • A Previous link to go to the preceding entry
  • A Next link to go to the following entry
  • An Entry X of Y counter showing your current position in the list

The navigation respects your View's current settings, including:

  • Sort order — If your View sorts entries alphabetically by last name, the Previous and Next links follow that same order
  • Filters — If your View uses Advanced Filters to show only specific entries, the pagination only includes those filtered entries
  • Approval status — Unapproved entries are automatically excluded from the navigation when the View is configured to show only approved entries
  • Trashed entries — Entries in the trash are always excluded

When you reach the first or last entry in the list, the corresponding Previous or Next link is automatically hidden.

Adding the code snippet

To add single entry pagination to your View, you need to add a PHP code snippet to your WordPress site. You can do this using a code snippets plugin (such as WPCode or Code Snippets) or by adding the code to your theme's functions.php   file.

1. Get the latest snippet

Copy the updated pagination snippet:

<?php
/**
 * GravityView Single Entry Navigation
 *
 * Adds "Entry X of Y" with Previous/Next links on single entry views.
 * Respects View sorting, approval status, active entry filters, and Advanced Filter conditions.
 *
 * Works with both CPT Views and shortcode-embedded Views.
 *
 * Usage: add this to your theme's functions.php or as a code snippet plugin.
 * The navigation will automatically appear at the bottom of single entry views.
 */


/**
 * Get single entry pagination links for GravityView 2.x+.
 *
 * @param \GV\Template_Context $context The template context provided by GravityView.
 *
 * @return string HTML output with entry count and navigation links.
 */
function gv_single_entry_navigation( $context ) {
	$view  = $context->view;
	$entry = $context->entry;

	if ( ! $view instanceof \GV\View || ! $view->form || ! $entry ) {
		return '';
	}

	// Override paging to retrieve ALL entries (not just one page).
	// Uses the View's full entry pipeline, which fires `gravityview/view/query`
	// so Advanced Filter, approval status, sorting, etc. are all applied.
	$remove_limit = function ( &$query ) {
		$query->limit( 5000 )->offset( 0 );
	};

	add_action( 'gravityview/view/query', $remove_limit, 9999 );

	$entries = $view->get_entries( gravityview()->request );

	remove_action( 'gravityview/view/query', $remove_limit, 9999 );

	$all_entries = $entries->all();

	if ( empty( $all_entries ) ) {
		return '';
	}

	// Find the current entry position in the sorted, filtered list.
	$current_id  = $entry->ID;
	$total_count = count( $all_entries );
	$position    = false;

	foreach ( $all_entries as $index => $gv_entry ) {
		if ( (string) $gv_entry->ID === (string) $current_id ) {
			$position = $index;
			break;
		}
	}

	if ( false === $position ) {
		return '';
	}

	$prev_pos = $position > 0 ? $position - 1 : false;
	$next_pos = $position < $total_count - 1 ? $position + 1 : false;

	$output  = '<div class="gv-entry-navigation" style="margin: 1em 0; display: flex; align-items: center; gap: 1em;">';

	if ( false !== $prev_pos ) {
		$prev_link = GravityView_API::entry_link( $all_entries[ $prev_pos ]->as_entry() );
		$output   .= '<a class="gv-entry-prev" href="' . esc_url( $prev_link ) . '">&larr; Previous</a>';
	}

	$output .= '<span class="gv-entry-count">Entry <strong>' . ( $position + 1 ) . '</strong> of <strong>' . $total_count . '</strong></span>';

	if ( false !== $next_pos ) {
		$next_link = GravityView_API::entry_link( $all_entries[ $next_pos ]->as_entry() );
		$output   .= '<a class="gv-entry-next" href="' . esc_url( $next_link ) . '">Next &rarr;</a>';
	}

	$output .= '</div>';

	return $output;
}


// Output navigation at the bottom of single entry views.
add_action( 'gravityview/template/after', function ( $context ) {
	if ( ! $context instanceof \GV\Template_Context ) {
		return;
	}

	if ( ! $context->entry ) {
		return;
	}

	echo gv_single_entry_navigation( $context );
} );

2. Add the snippet to your site

If you're using a code snippets plugin:

  1. Install and activate the plugin.
  2. Create a new snippet.
  3. Paste the code from the Gist.
  4. Set it to run on the frontend only.
  5. Save and activate the snippet.

If you're editing functions.php  :

  1. Navigate to Appearance > Theme File Editor.
  2. Select functions.php   from the file list.
  3. Paste the code at the end of the file.
  4. Click Update File.

Note: If you're using a parent theme, add the code to a child theme's functions.php   instead. This prevents your changes from being overwritten during theme updates.

3. Verify the pagination

  1. Open your View on the frontend.
  2. Click on any entry to open the Single Entry view.
  3. You should see "Previous" and "Next" links along with an "Entry X of Y" counter below the entry content.

Key details about the snippet

Feature Behavior
Hook used gravityview/template/after  
Placement Bottom of the Single Entry view
Sort order Matches the View's configured sort settings
Filtered entries Only includes entries matching the View's filters
Trashed entries Always excluded
Unapproved entries Excluded when "Show Only Approved" is enabled
Boundary behavior Previous link hidden on the first entry; Next link hidden on the last entry

Customizing the output

The snippet provides a function called gv_single_entry_navigation()   that returns the pagination HTML. By default, it hooks into gravityview/template/after   to display automatically. If you prefer to place the navigation manually in a custom template, you can:

  1. Remove the automatic hook by deleting the add_action   line from the snippet.
  2. Call echo gv_single_entry_navigation();   wherever you want the pagination to appear in your template.

You can also modify the HTML output within the function to change the styling, labels, or layout of the navigation controls.

Troubleshooting

The pagination links don't appear

  • Make sure you're viewing a single entry, not the main entries list.
  • Confirm the snippet is active and running on the frontend.
  • Check that the View has more than one entry. Pagination links are hidden when there's only one entry.

Entries appear in the wrong order

  • The pagination follows the View's sort order. Check your View's Settings and verify the Sort  By setting matches your expected order.

Some entries are skipped

  • If your View uses Advanced Filters, the pagination only includes entries that match those filters. Check your filter settings if entries seem to be missing.
  • Entries with a "Disapproved" or "Unapproved" approval status are excluded when the View's Show Only Approved setting is enabled.
Did this answer your question? Thanks for the feedback There was a problem submitting your feedback. Please try again later.

Still need help? Contact Us Contact Us