How to get number of a post over the total numbers of posts within a category in
-
I need to show a counter within my single page post (I use it as a shortcode).
I have a custom post type (slug = ‘portfolio’) that has different categories.
When I am in the single post, I want to display a counter such as “n/tot” where
n= the post number (first post within the category = 1; second post within the category = 2; etc) tot = total number of posts within that category
I found the way to show the total number of posts, but not within a category
add_shortcode( 'tot_posts', 'number_factsheets' ); function number_factsheets () { $total = wp_count_posts('portfolio')->publish; $output = '<div class="count">'; $output .= $total; $output .='</div>'; return $output; }
Is it possible to obtain the data above when I am in single page post? And how?
Viewing 5 replies - 1 through 5 (of 5 total)
Viewing 5 replies - 1 through 5 (of 5 total)
- The topic ‘How to get number of a post over the total numbers of posts within a category in’ is closed to new replies.