Created
October 30, 2014 17:45
-
-
Save lidocaine/cbc9942c52857fe28229 to your computer and use it in GitHub Desktop.
Useful Wordpress snippets I've had to come up with and will probably need to use again.
This file contains 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
/* | |
* | |
* Getting appropriate "X-Y of Z results" in searches | |
* with appropriate post numbering across pages | |
* | |
*/ | |
// Setting up variables for math to display | |
// proper search result counts across all pages... | |
$posts_per_page = get_option('posts_per_page'); | |
$page_num = (get_query_var('paged')) ? get_query_var('paged') - 1 : 0; | |
$offset = ($page_num) * $posts_per_page; | |
$page_total = $offset + $wp_query->post_count; | |
echo '<span class="search-result-count">'.($offset + 1).'-'.$page_total.' <em>of</em> .'$wp_query->found_posts.' results</span>'; | |
// To display the proper search result number we gotta do some more math... | |
// Must be used within The Loop to access $current_post | |
$real_index = ($wp_query->current_post + 1) + ( $posts_per_page * ($page_num) ); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment