Advertisement
Guest User

Untitled

a guest
Jun 12th, 2012
46
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.77 KB | None | 0 0
  1. <?php
  2. /*
  3. Plugin Name: Sports Theme Category Widget
  4. Description: This widget allows you to display posts from a category in any of the sidebar areas.
  5. Author: Jacob Martella
  6. Author URI:
  7. Version: 1.1
  8. */
  9.  
  10. add_action('widgets_init', create_function('', "register_widget('sports_category');"));
  11. class sports_category extends WP_Widget {
  12.  
  13. function sports_category() {
  14. $widget_ops = array( 'classname' => 'Sports Category Widget', 'description' => 'Use this widget to display posts from a category in any of your sidebars.' );
  15. $control_ops = array( 'width' => 500, 'height' => 250, 'id_base' => 'category' );
  16. $this->WP_Widget( 'category', 'sports_category', $widget_ops, $control_ops );
  17. }
  18.  
  19. function widget($args, $instance) {
  20. extract($args);
  21. $categoryslug = cat_id_to_slug($instance['category']); $categoryname = cat_id_to_name($instance['category']);
  22. ?>
  23. <!--Let's Start the Loop and Showing the Posts-->
  24.  
  25. <div id="widget-wrap">
  26. <?php query_posts('cat=' . $instance['category'] . 'showposts=1&orderby=date' ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  27.  
  28. <div id="category-widget-featured-photo">
  29. <?php the_post_thumbnail( 'cat-widget' ); ?>
  30. </div>
  31.  
  32. <h3 class="category-widget-main-headline">
  33. <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
  34. </h3>
  35.  
  36. <p class="postmetadata">
  37. Written By: <?php the_author_posts_link(); ?>, <?php $key="jobtitle"; get_post_meta($post->ID, $key, true); ?>
  38. </p>
  39.  
  40. <p class="story">
  41. <?php the_content(); ?>
  42. </p>
  43.  
  44. <p class="postmetadata">
  45. <?php the_time('F j, Y') ?> &bull; <?php comments_popup_link('0 comments', '1 comment', '% comments'); ?><?php edit_post_link('Edit', ' &bull; ', ''); ?>
  46. </p>
  47.  
  48. <?php endwhile; ?>
  49.  
  50. <?php rewind_query(); ?>
  51.  
  52. <p class="category-head">
  53. <a href="/<?php echo $categoryslug; ?>">Recent <?php echo $categoryname; ?> Stories</a>
  54. </p>
  55.  
  56. <?php query_posts('cat=' . $instance['category'] . 'showposts=3&orderby=date&offset=0' ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
  57.  
  58. <p class="category-widget-headlines">
  59. <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php the_time('F j, Y'); ?>
  60. </p>
  61.  
  62. <p class="viewall">
  63. <a href="<?php echo cat_id_to_slug($instance['category']); ?>">View All</a>
  64. </p>
  65.  
  66. <?php endwhile; ?>
  67.  
  68. <?php } ?>
  69.  
  70. <!--End Category Widget Display-->
  71.  
  72. <?php function update( $new_instance, $old_instance ) {
  73. $instance = $old_instance;
  74. $instance['title'] = $new_instance['title'];
  75. $instance['category'] = $new_instance['category'];
  76. return $instance;
  77. }
  78. ?>
  79.  
  80. <div style="float:left;width:230px;margin-right:20px;border-right:1px solid #aaaaaa;padding-right:10px;">
  81. <p style="font-weight:bold;text-decoration:underline;">Widget Content</p>
  82. <p>Select your category<br />
  83. <?php wp_dropdown_categories(array('selected' => $instance['category'], 'name' => $this->get_field_name( 'category' ), 'orderby' => 'Name', 'hierarchical' => 1, 'show_option_none' => __("None", 'studiopress'), 'hide_empty' => '0' )); ?>
  84. </p>
  85. <?php $categorytitle = cat_id_to_name($instance['category']); ?><input type="hidden" id="<?php echo $this->get_field_id('title'); ?>" name="<?php echo $this->get_field_name('title'); ?>" value="<?php echo $categorytitle; ?>" />
  86.  
  87. <?php }
  88. ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement