Round Rock / Austin, Texas
Drupal Web Developer

Check to see if Drupal Content Type in template.php

Check to see if Drupal Content Type in template.php

Today I came across some error messages on my Search Results page because I was checking for a content type in preprocess_page. Turns out I needed to add some extra code to make sure that I was on a node before checking the type. I've seen several approaches to this but this is what worked for me:

 

<?php

/* File: template.php */

function THEMENAME_preprocess_page(&$variables) {
    if (isset($variables['node']->type)) {
        $nodetype = $variables['node']->type;
      
        //if it is an 'article' content type
        if($nodetype == 'article'){
            //do special stuff for just articles here
        }
   }
}

?>

Drupal if Content Type