Forums

get current category (2 posts)

  1. dumdumsareyum
    Member
    Posted 3 years ago #

    I'm trying to use the following example from the codex that creates a dropdown list of categories:

    <select name="event-dropdown" onchange='document.location.href=this.options[this.selectedIndex].value;'>
     <option value=""><?php echo attribute_escape(__('Select Event')); ?></option>
     <?php
      $categories=  get_categories('child_of=10');
      foreach ($categories as $cat) {
      	$option = '<option value="/category/archives/'.$cat->category_nicename.'">';
    	$option .= $cat->cat_name;
    	$option .= ' ('.$cat->category_count.')';
    	$option .= '</option>';
    	echo $option;
      }
     ?>
    </select>

    But instead of 'child_of=10' I want it to list the child categories of the current category being queried. I see how to get the single title with single_cat_title()...is there something similar to get the category id? Thanks!

  2. esmi
    Theme Diva & Forum Moderator
    Posted 3 years ago #

    Try $cat_id = get_query_var('cat');

Topic Closed

This topic has been closed to new replies.

About this Topic