title: How to add a category and category path to Magento programatically?
body: <p>I'd like to export categories from one magento store and import to another one.</p>
  
  <p>The following information is part of categories which must to inserted in store. </p>
  
  <pre><code>Default Category    2
  All Categories  2/30
  Electronics 2/30/12
  TV &amp; Video  2/30/12/13
  </code></pre>
  
  <p>I try this following script to import one category but doesn't work. The script doesn't import the category.</p>
  
  <pre><code>require_once 'app/Mage.php';
  Mage::app('default'); // Default or your store view name.
  
  //get a new category object
  $category = Mage::getModel('catalog/category');
  $category-&gt;setStoreId(0); // 0 = default/all store view. If you want to save data for a specific store view, replace 0 by Mage::app()-&gt;getStore()-&gt;getId().
  
  //if update
  if ($id) {
    $category-&gt;load($id);
  }
  
  $general['name'] = "All Categories";
  $general['path'] = "2/30"; // catalog path
  $general['description'] = "";
  $general['meta_title'] = ""; //Page title
  $general['meta_keywords'] = "";
  $general['meta_description'] = "";
  $general['landing_page'] = ""; //has to be created in advance, here comes id
  $general['display_mode'] = "PRODUCTS_AND_PAGE"; //static block and the products are shown on the page
  $general['is_active'] = 1;
  $general['is_anchor'] = 0;
  $general['page_layout'] = 'two_columns_left';
  
  $category-&gt;addData($general);
  
  try {
      $category-&gt;save();
      echo "Success! Id: ".$category-&gt;getId();
  }
  catch (Exception $e){
      echo $e-&gt;getMessage();
  }
  </code></pre>