Support » Fixing WordPress » get_the_category() won't change between category requests

  • I have searched all over and can’t seem to find any help or docs on why get_the_category doesn’t change between category requests.

    Basically what I’m trying to do is have a custom sidebar display on certain categories.
    In category.php I have:

    $category = get_the_category();
    $category_slug = $category[0]->slug;

    and

    if ( in_array($category_slug, $pdi_cats) ) {
    
    	?>
        <div id="sidebar-container" class="cat-sidebar-<?php echo $category_slug; ?>">
    
    	<?php
    	if ( !function_exists('dynamic_sidebar') || !dynamic_sidebar( $category_slug . '-sidebar' ) ) {
    
    	}
    	?>
    
    	</div><!--sidebar-container-->
    	<?php
    
    } else {
    
    	get_sidebar();
    
    }

    which loops through my array of custom categories and if the current category is one of them displays that sidebar.

    The problem is that $category_slug won’t change when I change categories. It keeps displaying the first category that I pulled up like it’s caching it. Am I totally missing something here?

Viewing 2 replies - 1 through 2 (of 2 total)
Viewing 2 replies - 1 through 2 (of 2 total)
  • The topic ‘get_the_category() won't change between category requests’ is closed to new replies.