How to get the category ID (3 posts)

  1. just wondering
    Posted 5 years ago #

    I'm trying to get the category ID # to use in a switch statement.
    I've searched and have found a few things but can't get them to work.
    Basicly what I'm testing is this

    $category_id = get_cat_ID();
    echo "$category_id";

    Also do the permalinks effect this?

    Any pointers would be appreciated, Thanks

  2. Michael
    Forum Moderator
    Posted 5 years ago #

    is this in a category archive page?

    then try:

    $category_id = get_query_var('cat');

    if you are not clear with wordpress functions, look-up the codex:

  3. just wondering
    Posted 5 years ago #

    Thanks, that worked

    I had look at http://codex.wordpress.org/Function_Reference/get_cat_ID
    but couldn't get those examples to work.

    Thanks again

Topic Closed

This topic has been closed to new replies.

About this Topic