[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?

Austin Matzko if.website at gmail.com
Wed Oct 7 11:03:27 UTC 2009


On Wed, Oct 7, 2009 at 5:33 AM, Dave Mee <davemee at gmail.com> wrote:
> 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?

Either

$wp_query->get_queried_object()

or

$wp_query->get_queried_object_id()

should help you.


More information about the wp-hackers mailing list