Take the 2-minute tour ×
WordPress Development Stack Exchange is a question and answer site for WordPress developers and administrators. It's 100% free, no registration required.

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

CATEGORY.PHP

$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 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 at 18:08
    
See updated post –  FlannelBeard Jun 26 at 18:11

Your Answer

 
discard

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

Browse other questions tagged or ask your own question.