';
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 '
';
switch($field['type']) {
// case items will go here
// // text
case 'text':
echo '
'.$field['desc'].'';
break;
// checkbox
case 'checkbox':
echo '
';
break;
} //end switch
echo '
';
} // end foreach
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');