Forums

category id in archives page (5 posts)

  1. thibautr
    Member
    Posted 4 years ago #

    Can't seem to find this in the codex.

    How do I get the category id for the category i'm in in the archives page. ie. if i'm in http://www.example.com/flowers/

    how do i get the category id of the flowers category?

  2. SimonJ
    Member
    Posted 4 years ago #

    http://codex.wordpress.org/Template_Tags/get_the_category

    This code will output the cat ID you are in :

    <?php
    $cat = get_the_category();
    $cat = $cat[0];
    echo $cat->cat_ID;
    ?>

    S.

  3. CrazySerb
    Member
    Posted 3 years ago #

    That code doesn't work if a post is listed in more than one category, as it seems to display only the first category ID of the post listed on the archive page... which is the weirdest thing ever.

  4. jesseisrad
    Member
    Posted 3 years ago #

    Still no reply on this?

    Yes this code is not what we're looking for. Is there no way to pull the category ID of the category being listed on the archive page? I mean the URL shows it, so it has to be somewhere.

    thanks.

  5. jesseisrad
    Member
    Posted 3 years ago #

    Ah, I see the solution is here:

    http://wordpress.org/support/topic/223331?replies=3

    way to link to it.

Topic Closed

This topic has been closed to new replies.

About this Topic