Discover in this tutorial how to show the number of entries for a category in the title of your archive page using code.
When you have a blog or platform with many posts and you use categories to organize them, you may be interested in showing how many you have of each of them.
On OsomCode there are currently over 388 tutorials and, of those, 159 are for WordPress in general. This is something that visitors may not know at first glance, but if they visit the category, they will be able to see it quickly because I show it as part of the title.
This is the result:
Are you too interested in entering a number of entries in a category that is automatically updated in the title of your archive page?
Then read on. 😉
Instructions for displaying the number of category entries in the archive page
Add the following code at the end of functions.php or in your functionality plugin:
1. Add the number of entries to the title of the archive page
With this snippet you remove the default function (
genesis_do_taxonomy_title_description) and add a custom one to show the number of entries next to the title.
In addition, you use the
is_category() conditional tag and the
genesis_before_loop hook to place the text where you want it.
2. Customize the CSS of the title and description
Once you’ve got the number of entries displayed on the CPT archive page, all you need to do is assign the styles to make it look the way you want it to.
To do this, add this block to the end of style.css:
By inserting these CSS lines you increase and focus the size of both the title and description of the page.
Of course, you can modify it to your liking.
Now you know how to display the number of entries of a category on the category archive page and keep it always updated.
Now you just have to put it into practice. 😉
Any questions? Let me know in the comments.
And if you want to give me any suggestion for future tutorials, leave it in the contact form. Advantages of being a subscriber. 😉