title: Magento 1.7.0.2 - Call to member function getId() on a non-object in view.phtml (PHP Error)
body: <p>I am intermittently receiving the following error when accessing the product detail pages on our Magento website...</p>
  
  <pre><code>Call to member function getId() on a non-object in view.phtml (line 70)
  </code></pre>
  
  <p>The code that this error is referencing to can be found below...</p>
  
  <pre><code>&lt;?php
    $current_category = Mage::registry('current_category');
    $current_id = $current_category-&gt;getId();
  ?&gt;
  </code></pre>
  
  <p>The reason I'm using the code there is to display content specific to products within those categories. An example can be seen below...</p>
  
  <pre><code>&lt;?php if(($current_category) &amp;&amp; ($current_id == 717)):?&gt;
    // Code Here
  &lt;?php endif; ?&gt;
  </code></pre>
  
  <p>I don't know why this error is coming about intermittently, or if there is a way to replace the code entirely with something else but get the same end result. I'm really up for either but would appreciate any and all assistance with the matter.</p>
  
  <p>Thanks so much!</p>