true, 'labels' => array('name' => __('YSlides'), 'singular_name' => __("YSlide"), 'add_new' => "Add New YSlide", "edit_item" => "Edit YSlide", "new_item" => "Add New YSlide", "view_items" => "View YSlides"), 'supports' => array( 'title', 'thumbnail', 'editor' ) ); add_image_size('ys_image', 180, 240); register_post_type('ys_slides', $args); add_shortcode('ys-shortcode', 'ys_function'); } add_theme_support( 'post-thumbnails' ); add_action('init', 'ys_init'); /** * Add to Page Function */ function ys_function($type='ys_image'){ $args = array( 'post_type' => 'ys_slides', 'posts_per_page' => 10, 'meta_key' => 'custom_ys_checkbox', 'meta_value' => 'on' ); $result = '
'; $result .= ''; $result .= ''; //the loop $loop = new WP_Query($args); $num_posts = 0; if ($loop->have_posts() ) : while ($loop->have_posts()) : $loop->the_post(); $result .= '
'; $result .= "
"; $result .= get_the_post_thumbnail(null, 'ys_image'); $result .= "
"; $result .= "
"; $result .= "

".get_the_title().'

'; $result .= "
"; $result .= "

".get_the_content()."

"; $result .= "
"; $result .= ""; $result .= "
"; $result .= "
"; $result .= '
'; $num_posts++; endwhile; endif; if ($num_posts == 0){ $result .= '
'; $result .= "
"; $result .= "
"; $result .= "
"; $result .= "

Slides Missing

"; $result .= "
"; $result .= "

"; $result .= "
"; $result .= "
"; $result .= "
"; $result .= "
"; $result .= '
'; } $result .= "
"; for ($i = 0; $i < $num_posts; $i ++){ $result .= ""; } $result .= "
"; $result .='
'; wp_reset_postdata(); return $result; } //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// //Widget //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// class ys_slider_widget extends WP_Widget{ public function __construct(){ parent::__construct('ys_slider_widget', 'YaFed WP Slider', array('description' => __('A Slider Carousel', 'text_domain'))); } public function form($instance) { if (isset($instance['title'])) { $title = $instance['title']; } else { $title = __('Widget Slideshow', 'text_domain'); } ?>

'URL', 'desc' => '', 'id' => $prefix.'url', 'type' => 'text' ), array( 'label'=> 'Display on Slider?', 'desc' => '', 'id' => $prefix.'checkbox', 'type' => 'checkbox' ) ); // The Callback function show_custom_meta_box() { global $custom_meta_fields, $post; // Use nonce for verification echo ''; // Begin the field table and loop echo ''; foreach ($custom_meta_fields as $field) { // get value of this field if it exists for this post $meta = get_post_meta($post->ID, $field['id'], true); // begin a table row with echo ''; } // end foreach echo '
'; switch($field['type']) { // case items will go here // // text case 'text': echo '
'.$field['desc'].''; break; // checkbox case 'checkbox': echo ' '; break; } //end switch echo '
'; // end table } // Add the Meta Box function add_custom_meta_box() { add_meta_box( 'custom_ys_slider_meta', // $id 'Show on Slider', // $title 'show_custom_meta_box', // $callback 'ys_slides', // $page 'side', // $context 'high'); // $priority } add_action('add_meta_boxes', 'add_custom_meta_box'); // Save the Data function save_custom_meta($post_id) { global $custom_meta_fields; // verify nonce if (!wp_verify_nonce($_POST['custom_ys_meta_box_nonce'], basename(__FILE__))) return $post_id; // check autosave if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) return $post_id; // check permissions if ('page' == $_POST['post_type']) { if (!current_user_can('edit_page', $post_id)) return $post_id; } elseif (!current_user_can('edit_post', $post_id)) { return $post_id; } // loop through fields and save the data foreach ($custom_meta_fields as $field) { $old = get_post_meta($post_id, $field['id'], true); $new = $_POST[$field['id']]; if ($new && $new != $old) { update_post_meta($post_id, $field['id'], $new); } elseif ('' == $new && $old) { delete_post_meta($post_id, $field['id'], $old); } } // end foreach } add_action('save_post', 'save_custom_meta'); //////////////////////////////////////////////////////////////////////////////// //Carousel Style //////////////////////////////////////////////////////////////////////////////// function register_ys_styles(){ wp_register_style( 'YS-CSS', plugins_url("/style.css", __FILE__), array(), '1.0', 'all'); wp_enqueue_style( 'YS-CSS' ); } // Register style sheet. add_action( 'wp_enqueue_scripts', "register_ys_styles"); /** * Register JS functions */ function register_ys_scripts(){ wp_deregister_script('jquery'); wp_register_script('jquery', "http" . ($_SERVER['SERVER_PORT'] == 443 ? "s" : "") . "://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js", false, null); wp_enqueue_script('jquery'); wp_register_script('YSlider Script', plugins_url('/slider_script.js', __FILE__) , array('jquery'), '1.0', true); wp_enqueue_script( 'YSlider Script' ); } // Register Scripts add_action( 'init', 'register_ys_scripts');