Tuesday, May 7, 2013

Wordpress Create Category by php code

In Wordpress admin page every admin create their required category based on their need.  But while creating theme and separate plugin for some of the premium themes have a customization of selecting theme category. Here i will help you to create category on your php code.


The following line of function help you to add the category and sub categories.


function kv_create_category () {
$i=0;
$kv_category =array(
'Wordpress' => array('eCommerce', 
'SEO', 
'Social Networking', 
'Media', 
'Utilities', 
'Add-Ons', 
'Interface', 
'Themes', 
'Membership', 
'Plugins', 
'Miscellaneous' ),

'PHP' => array('Database',
'Gallery/Media',
'Polls',
'Project Mgt Tools',
'Graphs/Charts',
'Shopping Carts',
'Social Networking',
'Add-ons',
'Forms',
'Miscellaneous' ),

'Java Script' => array('Forms',
'Media',
'Project Mgt Tools',
'Charts/Graphs',
'Shopping Cart',
'Social Networks'),

'HTML5 & CSS' => array('Forms', 
'Tabs and Slider', 
'Buttons', 
'Animation', 
'Charts and Graphs', 
'Layout') ,

'Mobile' => array('iOS',
'Android',
'Native Web',
'Titanium',
'Java',
'Symbian'),

'Others' => array('facebook', 
'jQuery', 
'JS Slider', 
'Bootstrap', 
'Backlinks'), 

'.Net' => array('ASP',
'C#', 
'VB', 
'Others') 
);

foreach ($kv_category as $category => $datas) {
$cat_id=wp_create_category($category , $i++);
}
foreach ($kv_category as $category => $datas) {
$cat_id=get_cat_ID($category);
foreach ($datas as $data) {
        wp_create_category($data, $cat_id);
    }
}
}

No comments:

Post a Comment