I have two views, for taxonomy pages, one displays the products of the current term (using contextual filter "Content:has taxonomy term"), and other display the sub-categories of the term (using contextual filter "Taxonomy term: Parent term").

My problem is that I want to display product view only when I does not get any result in sub-category view.

2 Answers 2


I would use a block, then create a tpl.php file for the block and inside it put


$view = views_get_view('view_name_of_subcategory');
        // results are now stored as an array in $view->result
$count = count( $view->result );

if ($count = 0) { print views_embed_view('view_name_of_products','block_2' } 
else { print $view->render(); }


Replace block_1 & block_2 with your actual machine name, you can find it here (see picture)

enter image description here

PS if ($count = 0) does not work try if ($count = null)

  • thanks for your suggestion of using block. It gave me an idea to make block of my product list view, and then I displayed it only on required URLs(catalog/*). And then in block's PHP I added following code: <?php $v = views_get_view_result('uc_catalog_terms', 'default', arg(1)); $result = count($v); if ($result == 0) { return TRUE; } else { return FALSE; } ?>
    – Dev
    Oct 5, 2015 at 6:32

You can use the "NO RESULTS BEHAVIOR" from views (on the right side) and choose "Global: View area" to select your view you want to display if there aren't any results.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.