Example #1
0
 function otw_get_wp_items($item_type)
 {
     switch ($item_type) {
         case 'page':
             $pages = get_pages();
             $pages = otw_group_items($pages, 'ID', 'post_parent', 0);
             return $pages;
             break;
         case 'post':
             return get_posts(array('numberposts' => -1));
             break;
         case 'postsincategory':
             $categories = get_categories(array('hide_empty' => 0));
             $categories = otw_group_items($categories, 'cat_ID', 'parent', 0);
             return $categories;
             break;
         case 'postsintag':
             return get_terms('post_tag', '&orderby=name&hide_empty=0');
             break;
         case 'category':
             $categories = get_categories(array('hide_empty' => 0));
             $categories = otw_group_items($categories, 'cat_ID', 'parent', 0);
             return $categories;
             break;
         case 'posttag':
             return get_terms('post_tag', '&orderby=name&hide_empty=0');
             break;
         case 'pagetemplate':
             $templates = array();
             $all_templates = get_page_templates();
             if (is_array($all_templates) && count($all_templates)) {
                 foreach ($all_templates as $page_template_name => $page_template_script) {
                     $tplObject = new stdClass();
                     $tplObject->name = $page_template_name;
                     $tplObject->script = $page_template_script;
                     $templates[] = $tplObject;
                 }
             }
             return $templates;
             break;
         case 'archive':
             $archive_types = array();
             $a_types = array('daily' => __('Daily', 'otw_sbm'), 'monthly' => __('Monthly', 'otw_sbm'), 'yearly' => __('Yearly', 'otw_sbm'));
             foreach ($a_types as $a_type => $a_name) {
                 $aObject = new stdClass();
                 $aObject->ID = $a_type;
                 $aObject->name = $a_name;
                 $archive_types[] = $aObject;
             }
             return $archive_types;
             break;
         case 'customposttype':
             return get_post_types(array('public' => true, '_builtin' => false), 'object');
             break;
         case 'templatehierarchy':
             $h_types = array();
             $a_types = array('home' => __('Home', 'otw_sbm'), 'front' => __('Front Page', 'otw_sbm'), '404' => __('Error 404 Page', 'otw_sbm'), 'search' => __('Search', 'otw_sbm'), 'date' => __('Date', 'otw_sbm'), 'author' => __('Author', 'otw_sbm'), 'category' => __('Category', 'otw_sbm'), 'tag' => __('Tag', 'otw_sbm'), 'taxonomy' => __('Taxonomy', 'otw_sbm'), 'archive' => __('Archive', 'otw_sbm'), 'single' => __('Singular', 'otw_sbm'), 'attachment' => __('Attachment', 'otw_sbm'), 'page' => __('Page', 'otw_sbm'));
             foreach ($a_types as $a_type => $a_name) {
                 $aObject = new stdClass();
                 $aObject->ID = $a_type;
                 $aObject->name = $a_name;
                 $h_types[] = $aObject;
             }
             return $h_types;
             break;
         default:
             if (preg_match("/^cpt_(.*)\$/", $item_type, $matches)) {
                 return get_posts(array('post_type' => $matches[1], 'numberposts' => -1));
             } elseif (preg_match("/^ctx_(.*)\$/", $item_type, $matches)) {
                 return get_terms($matches[1], '&orderby=name&hide_empty=0');
             }
             break;
     }
 }
Example #2
0
 function otw_group_items($items, $id, $parent, $level, $sub_level = 0)
 {
     $result = array();
     if (is_array($items) && count($items)) {
         foreach ($items as $item) {
             if ($item->{$parent} == $level) {
                 $item->_sub_level = $sub_level;
                 $result[] = $item;
                 $sub_items = otw_group_items($items, $id, $parent, $item->{$id}, $sub_level + 1);
                 if (is_array($sub_items) && count($sub_items)) {
                     foreach ($sub_items as $s_item) {
                         $result[] = $s_item;
                     }
                 }
             }
         }
     }
     return $result;
 }