Support » Plugins and Hacks » Pull current category ID information

  • Hi,

    I need to be able to pull the current category’s ID, and that ID only.

    I’ve tried the following piece of code
    <?php foreach((get_the_category()) as $cat) { echo $cat->cat_ID . ' '; } ?>

    Whilst that does pull the current categories ID, it also appears to be pulling the last sub-category for the category’s ID.

    For example, Category 11 has a sub-category, Category 12.
    So when I’m on category 11s page, the above query spits out the following: 11%2012.

    I need it to only spit out 11 when I’m on parent category 11s page, and only spit out 12 when I’m on sub-category 12s page.

    Any ideas anyone?

Viewing 4 replies - 1 through 4 (of 4 total)
Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Pull current category ID information’ is closed to new replies.