Foxy Forum Status

We're no longer responding to questions via our forum, but we will keep it up for historical reasons. If you can't find the answer you're looking for, please visit our knowledge base or contact us. If there's enough interest in the future, we may bring the forum back.

Foxyshop: Parent category isn't getting an active class in the category widget

in Help edited May 2013
Hi,
As you can see on this page, I'm on the Chains parent category, but the parent category Chains isn't getting the active class, it going to the Body Chains child category.

http://sandbox.intrepidrealist.com/aya-papaya/product-cat/chains/


Can't figure out how to rectify this.

Thanks so much!
Comments
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    I've seen this in the past when you are pulling in a product so that the global post object gets confused. But what I'd do in this case to troubleshoot is to go into your helperfunctions.php file and find this line:
    $current_term_id = array($current_term_id);
    

    Put this after it print_r($current_term_id); to see what is actually getting passed in as the current term. That's the path to troubleshooting this particular issue.
  • Sorry about the delay in responding. I'm juggling hordes of projects!

    I put in this code and I don't see a visible difference on the page. What is supposed to happen?

    Thanks!
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    This is just supposed to show you what's in the $current_term_id field. If you don't see a difference, it might not be displaying it. The path to troubleshooting is to write something where you know you'll see it, then reload. Once you see it, then move it farther along till you don't see it. Watch those variables to see what the system is actually returning.
  • Hi sparkweb,
    I'm still having trouble with this.

    "The path to troubleshooting is to write something where you know you'll see it, then reload."

    I have no idea where to write something. Do you mean in the helper function or on the template file?

    When I'm on this page:

    http://sandbox.intrepidrealist.com/aya-papaya/product-cat/chains/

    I don't understand why "current" class isn't attached to chains, but to body chains

    When I'm on this page for earrings it appears to work:

    http://sandbox.intrepidrealist.com/aya-papaya/product-cat/earrings/

    What's throwing me off is that it's working for one and not the other...

    Thanks!
  • Hmmm...
    This code is showing up on the earrings category page after I added the print code:
    Array ( [0] => 20 ) Array ( [0] => 20 )
    

    Not sure what that means.
  • Also wanted to note I'm using the Foxyshop Category Widget in a custom sidebar..
  • fc_adamfc_adam FoxyCart Team
    @IntrepidRealist,

    Just a heads up, @sparkweb may be out for the next couple days - but I'm sure he'll get back to you as soon as he's able.
  • Thanks for the heads up!


  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    Sorry about the delay here. So what this means is that ID 20 is the current ID on the earring page - but there's something weird on the chains page because the print_r() code never shows up. Do you want to post your foxyshop_category_writer() function?
  • Here's what I got:
    function foxyshop_category_writer($category_id, $depth) {
    	global $foxyshop_category_write;
    	global $foxyshop_category_depth;
    	$args = array(
    		'hide_empty' => 0,
    		'hierarchical' => 0,
    		'parent' => $category_id,
    		'orderby' => 'name',
    		'order' => "ASC",
    	);
    	$termchildren = get_terms('foxyshop_categories', $args);
    	if ($termchildren) {
    
    
    		//Get Category Array For Product
    		if (get_post_type() == "foxyshop_product") {
    			global $post;
    			$current_term_id = wp_get_post_terms($post->ID, 'foxyshop_categories', array("fields" => "ids"));
    
    		//Get Current Category
    		} else {
    			$current_term_obj = get_term_by('slug', get_query_var('term'), "foxyshop_categories");
    			$current_term_id = $current_term_obj ? $current_term_obj->term_id : '';
    			$current_term_id = array($current_term_id);
    			print_r($current_term_id);
    		}
    
    
    		$termchildren = foxyshop_sort_categories($termchildren, $category_id);
    		if ($depth > 1) $foxyshop_category_write .= '<ul class="children">';
    		foreach ($termchildren as $child) {
    			$term = get_term_by('id', $child->term_id, "foxyshop_categories");
    			if (substr($term->name,0,1) == "_" || apply_filters('foxyshop_category_writer_skip', 0, $term)) continue;
    			$url = get_term_link($term, "foxyshop_categories");
    			$foxyshop_category_write .= '<li class="cat-item cat-item-' . $term->term_id . (in_array($term->term_id, $current_term_id) ? ' foxyshop-active-category' : '') . '">';
    			$foxyshop_category_write .= '<a href="' . $url . '">' . $term->name . '</a>';
    
    			if ($depth < $foxyshop_category_depth) {
    				$new_depth = $depth + 1;
    				foxyshop_category_writer($child->term_id, $new_depth);
    			}
    
    			$foxyshop_category_write .= "</li>\n";
    		}
    		if ($depth > 1) $foxyshop_category_write .= '</ul>';
    	}
    }
    

    Thanks!
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    The only way to fix this is to just keep moving the print_r(); around until you see it show up at all places. Because it isn't showing up on the other page it seems to indicate that there aren't term children because it never gets there.
  • sparkwebsparkweb Member, Integration Developer, FoxyShop, Order Desk
    Okay, I played around with this and was able to get it working, then I made a mistake and overwrote your foxyshop-single-category.php template file, so please update that one with your local file and you should be all set. I just had to rearrange how the helperfunctions was calling these. The other thing is that I would change your CSS :after to target the inner a because by doing it after the li --- well you'll see what it's doing when you replace the single category template.
  • I finally, got around to this. Having to deal with a sick kitty!
    It works wonderfully, and I profoundly appreciate your help!

    Thanks so much!
Sign In or Register to comment.