I am trying to display a post number (X) on each single.php, based on what number that post is in it’s category, followed by the total number of posts (Y) in the category.
So if there is 10 posts in my category “photos”, the latest post should be “1/10”.
I found this solution for Y:
<?php
$category = get_the_category();
echo $category[0]->category_count;
?>
This solution almost does what I want for X, but it is not based on category, and includes all posts:
http://wordpress.org/support/topic/show-post-number#post-1294235
Can anyone help? 🙂
Okay, this should do, what you want:
What is happening?
We fetch all posts of the current (main) category, ordered by Published date. That way, we already have the total number of posts in that category. Then we iterate through the posts and increment a counter variable to track the index of the current post. Finally, we display these numbers somewhere.