You could do it with a single line of code, but then again, you might want to add the code in other places, so a function is usually more useful.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 | function current_paged( $var = '' ) { if( empty( $var ) ) { global $wp_query; if( !isset( $wp_query->max_num_pages ) ) return; $pages = $wp_query->max_num_pages; } else { global $$var; if( !is_a( $$var, 'WP_Query' ) ) return; if( !isset( $$var->max_num_pages ) || !isset( $$var ) ) return; $pages = absint( $$var->max_num_pages ); } if( $pages < 1 ) return; $page = get_query_var( 'paged' ) ? get_query_var( 'paged' ) : 1; echo 'Page ' . $page . ' of ' . $pages; } |
If you like this question & answer and want to contribute, then write your question & answer and email to freewebmentor[@]gmail.com. Your question and answer will appear on FreeWebMentor.com and help other developers.