[wp-hackers] When archive.php is pulled in the theme, how does it know what category it applies to before (or as) the loop starts?

Mike Little mike at zed1.com
Wed Oct 7 11:09:02 UTC 2009


2009/10/7 Dave Mee <davemee at gmail.com>

> Hi List!
>
> I know it's possible to pull category names from the post in the loop on
> that page, but I need to find out what definitive category is being
> requested.
>
> For example - invoking site.com/category/cat-b will pull up an archive
> page.
> However, if the first post in that category is also a member of cat-a, my
> efforts to find a category name are thrown off kilter - the canonical
> category should be coming from the URL, rather than the individual posts.
>
> Is there some mechanism to look into the guts of wordpress or the query and
> discover which category it thinks it's dealing with?
>
> Dave
>
>
As one respondent mentioned single_cat_title() will get you the name of the
category. If you need the ID, the first line of that function uses
get_query_var():

   $cat = intval( get_query_var('cat') );

 Hope that helps,

Mike
-- 
Mike Little
http://zed1.com/


More information about the wp-hackers mailing list