Getting error
 "Can't use function return value in write context" on line #33.
 moved the line to
     $cat_id = get_query_var( 'cat' );
         $cat_id = (!empty($cat_id)) ? ($cat_id) : $categories[0]->cat_ID;

   PHP version compatibility i believe