Skip to main content
grammar fix
Source Link
Johannes Pille
  • 11.1k
  • 3
  • 42
  • 53

Given your posted query and that you seem to still be trying to figure it out:

First, off you should not use $wp_query = new WP_Query ();, since $wp_query is a global wordpress core object. Use any other variable to store the custom query in, $the_query = new WP_Query (); for instance.

That being said, the below code does what you want (if you did rename the query-storing variable $the_query).

$current_page = $the_query->query_vars['paged'];
$per_page = $the_query->query_vars['posts_per_page'];
$total_posts = intval($the_query->found_posts);
$first_paged_post = (($current_page - 1) * $per_page) + 1;
$last_paged_post = min($current_page * $per_page, $total_posts);

echo '<h3>On page '.$current_page.' - Showing #'.$first_paged_post;
// to account for the case where the last page has only one post (i.e. total of 13, 25) 
if ($last_paged_post != $first_paged_post) {
    echo ' - #'.$last_paged_post;
}
echo ' of '.$total_posts.' results for '.$size_name.', all colors, all genres</h3>';

NoteEdit, Note: While this is more copy&paste ready, it follows the same basic logic as Geert's snippet already provided.

Given your posted query and seem to still be trying to figure it out:

First, off you should not use $wp_query = new WP_Query ();, since $wp_query is a global wordpress core object. Use any other variable to store the custom query in, $the_query = new WP_Query (); for instance.

That being said, the below code does what you want (if you did rename the query-storing variable $the_query).

$current_page = $the_query->query_vars['paged'];
$per_page = $the_query->query_vars['posts_per_page'];
$total_posts = intval($the_query->found_posts);
$first_paged_post = (($current_page - 1) * $per_page) + 1;
$last_paged_post = min($current_page * $per_page, $total_posts);

echo '<h3>On page '.$current_page.' - Showing #'.$first_paged_post;
// to account for the case where the last page has only one post (i.e. total of 13, 25) 
if ($last_paged_post != $first_paged_post) {
    echo ' - #'.$last_paged_post;
}
echo ' of '.$total_posts.' results for '.$size_name.', all colors, all genres</h3>';

Note: While this is more copy&paste ready, it follows the same basic logic as Geert's snippet already provided.

Given your posted query and that you seem to still be trying to figure it out:

First, off you should not use $wp_query = new WP_Query ();, since $wp_query is a global wordpress core object. Use any other variable to store the custom query in, $the_query = new WP_Query (); for instance.

That being said, the below code does what you want (if you did rename the query-storing variable $the_query).

$current_page = $the_query->query_vars['paged'];
$per_page = $the_query->query_vars['posts_per_page'];
$total_posts = intval($the_query->found_posts);
$first_paged_post = (($current_page - 1) * $per_page) + 1;
$last_paged_post = min($current_page * $per_page, $total_posts);

echo '<h3>On page '.$current_page.' - Showing #'.$first_paged_post;
// to account for the case where the last page has only one post (i.e. total of 13, 25) 
if ($last_paged_post != $first_paged_post) {
    echo ' - #'.$last_paged_post;
}
echo ' of '.$total_posts.' results for '.$size_name.', all colors, all genres</h3>';

Edit, Note: While this is more copy&paste ready, it follows the same basic logic as Geert's snippet already provided.

Source Link
Johannes Pille
  • 11.1k
  • 3
  • 42
  • 53

Given your posted query and seem to still be trying to figure it out:

First, off you should not use $wp_query = new WP_Query ();, since $wp_query is a global wordpress core object. Use any other variable to store the custom query in, $the_query = new WP_Query (); for instance.

That being said, the below code does what you want (if you did rename the query-storing variable $the_query).

$current_page = $the_query->query_vars['paged'];
$per_page = $the_query->query_vars['posts_per_page'];
$total_posts = intval($the_query->found_posts);
$first_paged_post = (($current_page - 1) * $per_page) + 1;
$last_paged_post = min($current_page * $per_page, $total_posts);

echo '<h3>On page '.$current_page.' - Showing #'.$first_paged_post;
// to account for the case where the last page has only one post (i.e. total of 13, 25) 
if ($last_paged_post != $first_paged_post) {
    echo ' - #'.$last_paged_post;
}
echo ' of '.$total_posts.' results for '.$size_name.', all colors, all genres</h3>';

Note: While this is more copy&paste ready, it follows the same basic logic as Geert's snippet already provided.