[resolved] how to echo category id outside of the loop (3 posts)

  1. martin
    Posted 3 years ago #

    hi all,

    i want to display the category id of the current category outside of the loop. i tried it with <?php $thecatid = get_cat_ID( $cat_name ) ; echo $thecatid; ?> but it only returns me a '0'.
    i found a working solution in the forums get_cat_id( single_cat_title("",false) ) but i'm not sure if this is really a "clean" solution.

    thanks, martin

  2. alchymyth
    Forum Moderator
    Posted 3 years ago #

    in a category archive, this could be done with:

    <?php $thecatid = get_query_var('cat'); echo $thecatid; ?>

  3. martin
    Posted 3 years ago #

    it works

    thank you very much alchymyth

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.