title: Magento How to get The Parent Category of A Sub-Category from A Product
body: <pre><code>Root Category (id: 1)
   - Apparel (id: 2)
     -- Shirts (id:4)
     -- Pants  (id:5)
   - Accessories (id: 3)
     -- Handbags (id:6)
     -- Jewelry (id:7)
  </code></pre>
  
  <p>On Magento we can get the category Ids of a product by using <code>$productObj-&gt;getCategoryIds()</code> </p>
  
  <pre><code>$productObj = Mage::getModel('catalog/product')-&gt;load($product_id);
  $categoryIds =  $productObj-&gt;getCategoryIds();
  </code></pre>
  
  <p>Which will return an array of category Ids of the product. I have a specific need to get the first level parent of category of a product. Takes for example the category tree above, if a product is categorized in <strong>Pants</strong> category, I want to get the first level category which is <strong>Apparel</strong> (in this case, the product only tagged under <strong>Pants</strong> category but not tagged in <strong>Apparel</strong> category).</p>
  
  <p>Question: what method can I use to get the parent category of a sub category, or is it possible to get the first level category from a product?</p>