End goal is to find out if the current category is the child of a top level category.
If that’s all you want to do, the following should do it, though you might want to tweak it a little..
<?php
// Get current cat id or false
$current_cat = ( get_query_var('cat') ) ? (int) get_query_var('cat') : false;
// If category, get the term object, else false
$current_cat = ( $current_cat ) ? get_term_by( 'id' , $current_cat , 'category' ) : false;
// If a current category
if( $current_cat ) {
// Get the top level categories (do this after we've run a few checks to get a category - above)
$top_lvl_cats = get_terms( 'category', array(
'parent' => 0,
'hierarchical' => false,
'hide_empty' => false,
'fields' => 'ids'
) );
// See if the current category's parent is in the array of top level categories
if( in_array( $current_cat->parent , $top_lvl_cats ) ) {
// Result
echo 'The current category is a child of a top level category';
}
}
// Unset the variables after they've been used
unset( $current_cat , $top_lvl_cats );
?>