Advertisement
helgatheviki

WP_Alchemy Pages Drop Down

Jul 6th, 2011
317
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 2.42 KB | None | 0 0
  1. /* used to create dropdowns that list pages, posts and categories
  2. * use this in the metabox template:  
  3. *    $mb->the_field('destination'); alchified_dropdowns($mb);
  4. */
  5.  
  6. function alchified_dropdowns($mb, $showpages=TRUE, $showposts = TRUE, $showcats=TRUE){
  7.    
  8.     $dropdown = '<select class="destination" name="'. $mb->get_the_name() .'" value="'.$mb->get_the_value().'"/>';
  9.    
  10.     $dropdown .= '<option value="" style="font-weight: bold;">&mdash;'. __('None').'&mdash;</option>';
  11.            
  12.     $dropdown .= '<option value="custom" '. $mb->get_the_select_state('custom') .'>'. __("Custom").'</option>';
  13.            
  14.             if (class_exists('kia_signup_Widget')) {
  15.                 $dropdown .= '<option value="signup" '. $mb->get_the_select_state('signup') .'>'.  __("Signup Popup").'</option>';
  16.             }
  17.            
  18.             if ($showpages) {
  19.            
  20.                 $dropdown .= '<option value="" DISABLED>'.  __("Pages").'</option>';
  21.    
  22.                  //get all pages
  23.                 $pages = array();
  24.                 $pages_obj = get_pages('sort_column=post_title');    
  25.                 foreach ($pages_obj as $page) {
  26.                     $pages[$page->ID] = $page->post_title;
  27.                 }
  28.    
  29.                 foreach ($pages as $i => $page):
  30.                     $dropdown .= '<option value="page_'. $i .'" '. $mb->get_the_select_state('page_'.$i) .' style="font-style:italic;">&nbsp;&nbsp;&nbsp;&nbsp;'. $page .'</option>';
  31.                 endforeach;
  32.            
  33.             }
  34.            
  35.             if ($showposts) {
  36.            
  37.                 //get all posts
  38.                 $posts = array();
  39.                 $posts_obj = get_posts('sort_column=post_title');    
  40.                 foreach ($posts_obj as $post) {
  41.                 $posts[$post->ID] = $post->post_title; }
  42.  
  43.  
  44.                 $dropdown .= '<option value="" DISABLED>'.  __("Posts").'</option>';
  45.                
  46.                 foreach ($posts as $i => $post):
  47.                     $dropdown .= '<option value="post_'. $i .'" '. $mb->get_the_select_state('post_'.$i) .' style="font-style:italic;">&nbsp;&nbsp;&nbsp;&nbsp;'. $post .'</option>';
  48.                 endforeach;
  49.                
  50.             }
  51.    
  52.             if ($showcats) {
  53.    
  54.                 //get all categories
  55.                 $categories = array();  
  56.                 $categories_obj = get_categories('hide_empty=0');
  57.                 foreach ($categories_obj as $cat) {
  58.                 $categories[$cat->cat_ID] = $cat->name;}
  59.                
  60.                 $dropdown .= '<option value="" DISABLED>'.  __("Categories").'</option>';
  61.            
  62.                 foreach ($categories as $i => $category):
  63.                     $dropdown .= '<option value="category_'. $i .'" '. $mb->get_the_select_state('category_'.$i).' style="font-style:italic;">&nbsp;&nbsp;&nbsp;&nbsp;'. $category .'</option>';
  64.                 endforeach;
  65.             }
  66.    
  67.     $dropdown .= '</select>';  
  68.    
  69.     echo $dropdown;
  70. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement