Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- add_action("admin_init", "selection_meta_box");
- function selection_meta_box(){
- add_meta_box("featured-post", "Set Featured", "featured_post", "post", "side", "low");
- }
- function featured_post(){
- global $post;
- $meta_data = get_post_custom($post->ID);
- $featured_post = $meta_data["_featured_post"][0];
- $selected = ($meta_data["_featured_post"][0] == "yes") ? 'checked' : '';
- echo "<p>";
- echo "<input $selected type='checkbox' name='featured_post' value='yes' />";
- echo "<label>Select this post as Featured.</label>";
- echo "</p>";
- }
- add_action('save_post', 'save_post_details');
- function save_post_details(){
- global $post;
- if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
- return;
- $featured_post = trim($_POST["featured_post"]);
- update_post_meta($post->ID, "_featured_post", $featured_post);
- }
- function show_featured_posts($numbers) {
- global $post;
- //get $numbers of featured posts
- $featured_posts_array = get_posts( 'meta_key=_featured_post&meta_value=yes&numberposts='.$numbers.'&post_status=publish');
- $output .= '<div class="slider-wrapper theme-default">';
- $output .= '<div class="ribbon"></div>';
- $output .= '<div id="slider" class="nivoSlider">';
- foreach ($featured_posts_array as $post) : setup_postdata($post);
- $nivo_title = "#nivo".get_the_ID(); //assign the postID as title of the image
- if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) {
- $output .= get_the_post_thumbnail(get_the_ID(), array(800,400), array( "class" => "post_thumbnail", 'title' => $nivo_title )); }
- $caption .= "<div id='nivo".get_the_ID()."' class='nivo-html-caption'>
- <h2><a href='".get_permalink()."'>".get_the_title()."</a></h2>
- ".get_the_excerpt()."
- </div>";
- endforeach;
- $output .= '</div>';
- $output .= $caption;
- $output .= '</div>';
- return $output;
- //reset WP query
- wp_reset_query();
- }
- function include_nivo_scripts() {
- wp_deregister_script( 'jquery' );
- wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
- wp_register_script( 'nivopack', get_bloginfo('template_directory').'/lib/js/jquery.nivo.slider.pack.js');
- wp_enqueue_script( 'jquery' );
- wp_enqueue_script( 'nivopack' );
- }
- add_action('wp_enqueue_scripts', 'include_nivo_scripts');
- add_action('wp_print_styles', 'add_nivo_stylesheets');
- function add_nivo_stylesheets() {
- wp_register_style('nivo_theme_style', get_bloginfo('template_directory').'/themes/default/default.css');
- wp_register_style('nivo_main_style', get_bloginfo('template_directory').'/lib/js/nivo-slider.css');
- wp_enqueue_style( 'nivo_theme_style');
- wp_enqueue_style( 'nivo_main_style');
- }
- add_action('wp_footer', 'nivo_functioncall');
- function nivo_functioncall() {
- echo '<script type="text/javascript">
- $(window).load(function() {
- $("#slider").nivoSlider();
- });
- </script>';
- }
- function tg_featured_posts($atts, $content = null) {
- extract(shortcode_atts(array(
- "numbers" => '5'
- ), $atts));
- echo show_featured_posts($numbers);
- }
- add_shortcode('featured', 'tg_featured_posts');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement