How to move custom code into template.php In my node.tpl.php file I have this custom code:
&lt;?php if($node-&gt;field_division['und'][0]['value'] = 1): 
    $cta = $GLOBALS['base_url'].'/node/6';
elseif($node-&gt;field_division['und'][0]['value'] = 2): 
    $cta = $GLOBALS['base_url'].'/node/7';
endif;
?&gt;

I want to move it to my template.php file, so I can access it both from node.tpl.php and page.tpl.php.
How can I do this?
I tried following the examples in this thread and this article but I can't get it to work. Any help would be greatly appreciated.
First off, don't use 'und'. You should use field_get_items(). This is a change from D6, which is likely why you can't use those articles as a reference.

Secondly, you are using = and not ==, so you're assigning the value instead of comparing it.

So, you can probably just do the following:

function THEMENAME_preprocess_node(&amp;$variables) {
  THEMENAME_field_division_helper($variables);
}

function THEMENAME_preprocess_page(&amp;$variables) {
  THEMENAME_field_division_helper($variables);
}

function THEMENAME_field_division_helper(&amp;$variables) {
  if ($node = $variables['node']) {
    $field_division = field_get_items('node', $node, 'field_division');
    if ($field_division[0]['tid'] == 1) {
      $variables['cta'] = $GLOBALS['base_url'].'/node/6';
    }
    else if ($field_division[0]['tid'] == 2) {
      $variables['cta'] = $GLOBALS['base_url'].'/node/6';
    }
  }
}


And then in your node.tpl.php and page.tpl.php file,

&lt;?php if (isset($cta)): ?&gt;
  &lt;div class="some-wrapper"&gt;
    &lt;?php print $cta; ?&gt;
  &lt;/div&gt;
&lt;?php endif; ?&gt;