Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /*
- Plugin Name: Sports Theme Category Widget
- Description: This widget allows you to display posts from a category in any of the sidebar areas.
- Author: Jacob Martella
- Author URI:
- Version: 1.1
- */
- add_action('widgets_init', create_function('', "register_widget('sports_category');"));
- class sports_category extends WP_Widget {
- function sports_category() {
- $widget_ops = array( 'classname' => 'Sports Category Widget', 'description' => 'Use this widget to display posts from a category in any of your sidebars.' );
- $control_ops = array( 'width' => 500, 'height' => 250, 'id_base' => 'category' );
- $this->WP_Widget( 'category', 'sports_category', $widget_ops, $control_ops );
- }
- function widget($args, $instance) {
- extract($args);
- $categoryslug = cat_id_to_slug($instance['category']); $categoryname = cat_id_to_name($instance['category']);
- ?>
- <!--Let's Start the Loop and Showing the Posts-->
- <div id="widget-wrap">
- <?php query_posts('cat=' . $instance['category'] . 'showposts=1&orderby=date' ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
- <div id="category-widget-featured-photo">
- <?php the_post_thumbnail( 'cat-widget' ); ?>
- </div>
- <h3 class="category-widget-main-headline">
- <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a>
- </h3>
- <p class="postmetadata">
- Written By: <?php the_author_posts_link(); ?>, <?php $key="jobtitle"; get_post_meta($post->ID, $key, true); ?>
- </p>
- <p class="story">
- <?php the_content(); ?>
- </p>
- <p class="postmetadata">
- <?php the_time('F j, Y') ?> • <?php comments_popup_link('0 comments', '1 comment', '% comments'); ?><?php edit_post_link('Edit', ' • ', ''); ?>
- </p>
- <?php endwhile; ?>
- <?php rewind_query(); ?>
- <p class="category-head">
- <a href="/<?php echo $categoryslug; ?>">Recent <?php echo $categoryname; ?> Stories</a>
- </p>
- <?php query_posts('cat=' . $instance['category'] . 'showposts=3&orderby=date&offset=0' ); if ( have_posts() ) : while ( have_posts() ) : the_post(); ?>
- <p class="category-widget-headlines">
- <a href="<?php the_permalink(); ?>"><?php the_title(); ?></a> <?php the_time('F j, Y'); ?>
- </p>
- <p class="viewall">
- <a href="<?php echo cat_id_to_slug($instance['category']); ?>">View All</a>
- </p>
- <?php endwhile; ?>
- <?php } ?>
- <!--End Category Widget Display-->
- <?php function update( $new_instance, $old_instance ) {
- $instance = $old_instance;
- $instance['title'] = $new_instance['title'];
- $instance['category'] = $new_instance['category'];
- return $instance;
- }
- ?>
- <div style="float:left;width:230px;margin-right:20px;border-right:1px solid #aaaaaa;padding-right:10px;">
- <p style="font-weight:bold;text-decoration:underline;">Widget Content</p>
- <p>Select your category<br />
- <?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' )); ?>
- </p>
- <?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; ?>" />
- <?php }
- ?>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement