Hide html / code based on content type I'm using a block of code that shouldn't be displayed on certain content types (not blocks, but actual code). When I use this approach, I'm getting undefined variable and trying to get property of non-object errors:

&lt;?php
    if(function_exists('views_get_page_view') &amp;&amp; views_get_page_view() ||  arg(0) == 'user') {
      $showpage = "yes";
    }
?&gt;

&lt;?php if (((!empty($node)) || (!empty($showpage))) &amp;&amp; (($node-&gt;type != 'article') &amp;&amp; ($node-&gt;type != 'basic_page'))): ?&gt;

(Show all this)

&lt;?php endif; ?&gt;


It's the check if the visitor is on a user related page that causes the errors, but I have no idea how to fix this. Can someone help me out?
$node isn't available on user pages. But when $showpage is set, you are checking a property on the $node object. This gets the two errors you are describing. 

I'm not sure what you are trying to do but you can troubleshoot by breaking out your booleans. I find it helpful to break logic onto multiple lines whenever possible, so that other people (and I) can read it later.

From:

if (((!empty($node)) || (!empty($showpage))) &amp;&amp; (($node-&gt;type != 'article') &amp;&amp; ($node-&gt;type != 'basic_page'))):


To:

if (!empty($node) || !empty($showpage)) {
  if ($node-&gt;type != 'article' &amp;&amp; $node-&gt;type !='basic_page') {
    // do that stuff
  }
} 


So - when $showpage is not empty but $node is, as on a user page, $node is undefined. 

I'm not exactly sure what you are trying to do but I think it is along the lines of "show this stuff on node pages that are not basic page and not article, or when the $showpage variable is present. 

In which case:

if ((!empty($node) &amp;&amp; !in_array($node-&gt;type, array('article', 'basic_page'))) || !empty($showpage))


Or more readably,

if(function_exists('views_get_page_view') &amp;&amp; views_get_page_view() ||  arg(0) == 'user') {
  $showpage = 'yes';
}
elseif (!empty($node) &amp;&amp; !in_array($node-&gt;type, array('article', 'basic_page'))) {
  $showpage = 'yes';
}

if (!empty($showpage)) {
  // do that stuff
}


It isn't a one-liner, but the longer code is easier to read, troubleshoot, and prevent errors.