Advertisement
Guest User

Untitled

a guest
Jul 16th, 2012
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. add_action("admin_init", "selection_meta_box");
  2.  
  3. function selection_meta_box(){
  4. add_meta_box("featured-post", "Set Featured", "featured_post", "post", "side", "low");
  5. }
  6.  
  7. function featured_post(){
  8. global $post;
  9. $meta_data = get_post_custom($post->ID);
  10. $featured_post = $meta_data["_featured_post"][0];
  11. $selected = ($meta_data["_featured_post"][0] == "yes") ? 'checked' : '';
  12. echo "<p>";
  13. echo "<input $selected type='checkbox' name='featured_post' value='yes' />";
  14. echo "<label>Select this post as Featured.</label>";
  15. echo "</p>";
  16. }
  17.  
  18. add_action('save_post', 'save_post_details');
  19.  
  20. function save_post_details(){
  21. global $post;
  22. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE )
  23. return;
  24. $featured_post = trim($_POST["featured_post"]);
  25. update_post_meta($post->ID, "_featured_post", $featured_post);
  26. }
  27.  
  28. function show_featured_posts($numbers) {
  29. global $post;
  30. //get $numbers of featured posts
  31. $featured_posts_array = get_posts( 'meta_key=_featured_post&meta_value=yes&numberposts='.$numbers.'&post_status=publish');
  32. $output .= '<div class="slider-wrapper theme-default">';
  33. $output .= '<div class="ribbon"></div>';
  34. $output .= '<div id="slider" class="nivoSlider">';
  35. foreach ($featured_posts_array as $post) : setup_postdata($post);
  36. $nivo_title = "#nivo".get_the_ID(); //assign the postID as title of the image
  37. if ( function_exists("has_post_thumbnail") && has_post_thumbnail() ) {
  38. $output .= get_the_post_thumbnail(get_the_ID(), array(800,400), array( "class" => "post_thumbnail", 'title' => $nivo_title )); }
  39. $caption .= "<div id='nivo".get_the_ID()."' class='nivo-html-caption'>
  40. <h2><a href='".get_permalink()."'>".get_the_title()."</a></h2>
  41. ".get_the_excerpt()."
  42. </div>";
  43. endforeach;
  44. $output .= '</div>';
  45. $output .= $caption;
  46. $output .= '</div>';
  47. return $output;
  48. //reset WP query
  49. wp_reset_query();
  50. }
  51.  
  52. function include_nivo_scripts() {
  53. wp_deregister_script( 'jquery' );
  54. wp_register_script( 'jquery', 'http://ajax.googleapis.com/ajax/libs/jquery/1.6/jquery.min.js');
  55. wp_register_script( 'nivopack', get_bloginfo('template_directory').'/lib/js/jquery.nivo.slider.pack.js');
  56. wp_enqueue_script( 'jquery' );
  57. wp_enqueue_script( 'nivopack' );
  58. }
  59.  
  60. add_action('wp_enqueue_scripts', 'include_nivo_scripts');
  61.  
  62. add_action('wp_print_styles', 'add_nivo_stylesheets');
  63. function add_nivo_stylesheets() {
  64. wp_register_style('nivo_theme_style', get_bloginfo('template_directory').'/themes/default/default.css');
  65. wp_register_style('nivo_main_style', get_bloginfo('template_directory').'/lib/js/nivo-slider.css');
  66. wp_enqueue_style( 'nivo_theme_style');
  67. wp_enqueue_style( 'nivo_main_style');
  68. }
  69.  
  70. add_action('wp_footer', 'nivo_functioncall');
  71. function nivo_functioncall() {
  72. echo '<script type="text/javascript">
  73. $(window).load(function() {
  74. $("#slider").nivoSlider();
  75. });
  76. </script>';
  77. }
  78.  
  79. function tg_featured_posts($atts, $content = null) {
  80. extract(shortcode_atts(array(
  81. "numbers" => '5'
  82. ), $atts));
  83. echo show_featured_posts($numbers);
  84. }
  85. add_shortcode('featured', 'tg_featured_posts');
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement