WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I am trying to register an "active" class on my li if the category matches the page. If you click the horror category it will show you a loop with all the videos in that category. But the button for horror does not show an active class. I know I need an if else statement but the things I have tried simply do not work and break the site. Im not good enough with PHP or Wordpress to really figure this out.

Site here


$args = array(
        'orderby' => 'name',
        'parent' => 0
      $categories = get_categories( $args );
      foreach ( $categories as $category ) {
        echo '<li> <a class="browse-categories" href="' . get_category_link( $category->term_id ) . '">' . $category->name . '</a> </li>';

Can something like this do the trick?

if ( $category->slug == $category->term_id )
share|improve this question
you're only populating $post_cats if you're on a category page, and you're only trying to compare each category ID to the post's categories if you're on a single post, those two conditions will never align. – Milo Jun 26 '14 at 17:39
Thanks for your response. Im still new to Wordpress. I see what you are saying, a lot of what I have done thus far is kind of stumbled upon in the first place. 1. Is there a better way to write this, if so then how? And 2. How can I get them to align to write a proper if else function? – FlannelBeard Jun 26 '14 at 18:08
See updated post – FlannelBeard Jun 26 '14 at 18:11

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.