• Resolved jakemc

    (@jakemc)


    Hi. I want to link to category related content from the archive page (for example a particular discussion forum).

    So I would like to identify the current category being viewed on the archive/category page. In other words something similar to single_cat_title() such as single_cat_id() or single_cat_object() which return a value/object to PHP. Functions such as get_categories only seem to work when a post is defined (which may belong to more than one category)

    Any suggestions? Thanks in advance.

Viewing 4 replies - 1 through 4 (of 4 total)
  • I just needed that.. apparently the variable $cat holds the current category ID.

    Thread Starter jakemc

    (@jakemc)

    I hadn’t realised it was quite that simple! Thanks Jonski.

    Do you know if it’s possible to get the other category attributes from the ID without going directly to the database (using get_var of course)?

    There may be an easier way than this, I tend to stumble around until I find something that works, but I wanted the slug so…

    $this_category = get_category($cat);
    echo $this_category->category_nicename;

    ..gives you the slug. You can see all the info that is available that way by having a nosey around in the database, but there may be a list somewhere.

    Thread Starter jakemc

    (@jakemc)

    Great. Thanks Jonski.

Viewing 4 replies - 1 through 4 (of 4 total)
  • The topic ‘Get the category id on the archive page’ is closed to new replies.