How to make a specific template according number of nodes in a content type?
I don't know how to swap template files with panels I only know how to modify the layout based on condition, sorry. here's a small little snippet i quickly wrote to display a different template based on the number of nodes inside of the content type. This should really be done with a custom module but I don't have time.


Make sure templates are in template folder under your theme and named correctly.
Copy paste snippet below into your template.php file.

function YOURTHEME_preprocess_node(&amp;$vars) {

if($vars['type'] == 'article'){
     // set content type
     $content_type = 'article';

     // Count number of articles in article
     $query = "SELECT COUNT(*) amount 
               FROM {node} n ".
              "WHERE n.type = :type";
     $result = db_query($query, array(':type' =&gt; $content_type))-&gt;fetch();

     // get number of articles
     $articleCount = $result-&gt;amount;

     //specify template based on number of articles
     // one - is equal to _ and two -- is equal to __ for template file
     // No need to add `.tpl.php`
     if($articleCount == 1){
         $vars['theme_hook_suggestion'] = 'page__template1';
     }
     if($articleCount == 2){
         $vars['theme_hook_suggestion'] = 'page__template2';
     }
     if($articleCount == 3){
         $vars['theme_hook_suggestion'] = 'page__template3';
     }
     // ect.... you should make a dynamic loop here this is just basic logic.
   }
}

Modify code to your liking
Clear Cache