Skip to content

Instantly share code, notes, and snippets.

@kodie
Last active July 23, 2019 19:35
Show Gist options
  • Save kodie/3f6235ba0854c21cf1f6ceb0c7542848 to your computer and use it in GitHub Desktop.
Save kodie/3f6235ba0854c21cf1f6ceb0c7542848 to your computer and use it in GitHub Desktop.
WordPress pagination indicator "Showing 20 – 29 of 138 posts"
<?php
$paged = max(1, (int) $wp_query->query_vars['paged']);
$first_post_index = $paged === 1 ? 1 : ((($paged - 1) * (int) $wp_query->query_vars['posts_per_page']) + 1);
$last_post_index = (($first_post_index + (int) $wp_query->post_count) - 1);
echo "Showing {$first_post_index} – {$last_post_index} of {$wp_query->found_posts} posts";
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment