Capture Category ID on Category Archive Page? (4 posts)

  1. fredhead
    Posted 6 years ago #


    Can't find info on this anywhere in Codex or forum. On a category archive page for a parent category, I want to display in a line of links the child categories for that parent category.

    I even tried brute force, grabbing the cat= value from the query string (e.g. $catID = $_GET['cat'];) but that doesn't appear to work when running mod_rewrite.

    If I'm not mistaken, I can run wp_list_categories but I need the category parent id. That's the piece that I need to know how to get it within the WP system.

    Thanks for any ideas!

  2. esmi
    Forum Moderator
    Posted 6 years ago #

    Try using <?php $this_category = get_category($cat);?>. you can then reference the category id using $this_category->cat_ID.

  3. fredhead
    Posted 6 years ago #

    Thanks, esmi, but it didn't work. Here's what I've got for a parent category archive page:

    $this_category = get_category($cat);

    I want this sort of output:

    Child Category 1 | Child Category 2 | Child Category 3

    Any help would be much appreciated. I'm bummed it is so hard to do something that to me, at least, seems rather basic and common.


  4. Mark / t31os

    Posted 6 years ago #

    echo get_query_var('cat');

    Will output the ID of the current category..

Topic Closed

This topic has been closed to new replies.

About this Topic


No tags yet.