<?php include XOOPS_ROOT_PATH . "/class/xoopsformloader.php"; $form = new XoopsThemeForm($form_title, $form_id, "categories.php"); $form->addElement(new XoopsFormText(_LANG_C_NAME_SUBCAT, "cat_name", 50, 150, $cat_name), true); $formcat = new XoopsFormSelect(_LANG_C_NAME_PARENT, "cat", $category_parent); $formcat->addOption("0", 'None'); wp_dropdown_cats_xoops($formcat, $cat_ID, $category_parent); $form->addElement($formcat); $form->addElement(new XoopsFormTextArea(_LANG_C_NAME_CATDESC . "(optional)", "category_description", $category_description, 10, 80)); if ($form_id == 'addcat') { $form->addElement(new XoopsFormButton("", "submit", _LANG_C_NAME_ADDBTN, "submit")); $form->addElement(new XoopsFormHidden("action", "addcat")); } elseif ($form_id == 'editcat') { $form->addElement(new XoopsFormButton("", "submit", _LANG_C_NAME_EDITBTN, "submit")); $form->addElement(new XoopsFormHidden("cat_ID", $cat_ID)); $form->addElement(new XoopsFormHidden("action", "editedcat")); } $form->display();
function wp_dropdown_cats_xoops(&$formSelect, $currentcat, $currentparent = 0, $parent = 0, $level = 0, $categories = 0) { global $wpdb, $wp_id, $bgcolor; if (!$categories) { $categories = $wpdb->get_results("SELECT * FROM {$wpdb->categories[$wp_id]} ORDER BY cat_name"); } if ($categories) { foreach ($categories as $category) { if ($currentcat != $category->cat_ID && $parent == $category->category_parent) { $pad = str_repeat('– ', $level); $formSelect->addOption($category->cat_ID, "{$pad}{$category->cat_name}"); wp_dropdown_cats_xoops($formSelect, $currentcat, $currentparent, $category->cat_ID, $level + 1, $categories); } } } else { return false; } }