I'd like to import a long list of categories into ExpressionEngine and create new categories. Is there an easy way to do this, either via add-on, or some handy PHP code?
Use DataGrab -- http://devot-ee.com/add-ons/datagrab -- and import with a spreadsheet. If you have only one level for categories, it's super easy. If you have category levels or categories with same name, it's a little more complicated.
If you have levels, your spreadsheet (csv is best, IMO) can be created safely following these steps.
- In EE, create the first top-level category. Note its cat_id.
- Export the exp_categories table from your database (or create a spreadsheet with the exact same columns as that table).
- Add a new row for a new category (best to keep it in order for sanity's sake). If the next category is a child of the first category your entered in EE, make sure to the parent category's id as this category's parent_id. Also, this category would have a cat_id one number higher than the first one you created.
- Keep adding rows like that.
If you have categories with the same name, make sure to give them a unique cat_url_title.