When I query the category (category.php), how do I get the title of the current category, ie., the one that is being queried?
And how do I get the title for tag and date (be it the day, the month or the year)?
When I query the category (category.php), how do I get the title of the current category, ie., the one that is being queried?
And how do I get the title for tag and date (be it the day, the month or the year)?
You must be logged in to post a comment.
For category use
single_cat_title
function:http://codex.wordpress.org/Function_Reference/single_cat_title
For tag use
single_tag_title
function:http://codex.wordpress.org/Function_Reference/single_tag_title
For date use
get_the_date
function:http://codex.wordpress.org/Function_Reference/get_the_date
For example if you open twentyten theme you will see following:
category.php:
date.php:
In addition to the other answers, you can call:
single_term_title('Currently browsing: ')
to display ‘Currenty browsing term’ (where term is the name of the taxonomy term you are viewing. (See Codex)This works for custom taxonomies as well category and tag terms.
Also, you might find it easier to use
wp_title
which handles taxonomies and archives, displaying the appropriate title depending on what you are viewing. It essentially switches through all the available functions for displaying titles so you might want to take a look at the source code. Others include:single_post_title()
for postsget_the_date()
for date based archivesTry the following
See the Codex for more on formatting the date: HERE
PS. These are to be called within the loop. Except the first two which must be outside the loop.
Thank you for your replies! I made this for date:
for archive.php
then just
This is probably more than you need right now, but is probably something you will need on other areas of your theme.
This code gets the category name of the current post, then displays it as a link to the posts listed in the category via the category.php file.