Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /* used to create dropdowns that list pages, posts and categories
- * use this in the metabox template:
- * $mb->the_field('destination'); alchified_dropdowns($mb);
- */
- function alchified_dropdowns($mb, $showpages=TRUE, $showposts = TRUE, $showcats=TRUE){
- $dropdown = '<select class="destination" name="'. $mb->get_the_name() .'" value="'.$mb->get_the_value().'"/>';
- $dropdown .= '<option value="" style="font-weight: bold;">—'. __('None').'—</option>';
- $dropdown .= '<option value="custom" '. $mb->get_the_select_state('custom') .'>'. __("Custom").'</option>';
- if (class_exists('kia_signup_Widget')) {
- $dropdown .= '<option value="signup" '. $mb->get_the_select_state('signup') .'>'. __("Signup Popup").'</option>';
- }
- if ($showpages) {
- $dropdown .= '<option value="" DISABLED>'. __("Pages").'</option>';
- //get all pages
- $pages = array();
- $pages_obj = get_pages('sort_column=post_title');
- foreach ($pages_obj as $page) {
- $pages[$page->ID] = $page->post_title;
- }
- foreach ($pages as $i => $page):
- $dropdown .= '<option value="page_'. $i .'" '. $mb->get_the_select_state('page_'.$i) .' style="font-style:italic;"> '. $page .'</option>';
- endforeach;
- }
- if ($showposts) {
- //get all posts
- $posts = array();
- $posts_obj = get_posts('sort_column=post_title');
- foreach ($posts_obj as $post) {
- $posts[$post->ID] = $post->post_title; }
- $dropdown .= '<option value="" DISABLED>'. __("Posts").'</option>';
- foreach ($posts as $i => $post):
- $dropdown .= '<option value="post_'. $i .'" '. $mb->get_the_select_state('post_'.$i) .' style="font-style:italic;"> '. $post .'</option>';
- endforeach;
- }
- if ($showcats) {
- //get all categories
- $categories = array();
- $categories_obj = get_categories('hide_empty=0');
- foreach ($categories_obj as $cat) {
- $categories[$cat->cat_ID] = $cat->name;}
- $dropdown .= '<option value="" DISABLED>'. __("Categories").'</option>';
- foreach ($categories as $i => $category):
- $dropdown .= '<option value="category_'. $i .'" '. $mb->get_the_select_state('category_'.$i).' style="font-style:italic;"> '. $category .'</option>';
- endforeach;
- }
- $dropdown .= '</select>';
- echo $dropdown;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement