PluginProbe
Category Posts Block / 2.3
Category Posts Block v2.3
5.0.0 trunk 1.0 1.1 1.2 1.2.1 1.3 1.3.1 1.3.2 1.3.3 2.0 2.1 2.2 2.3 3.1 3.2 3.3 4.0 4.1.0 4.1.1 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 All 62 releases
category-posts / cat-posts.php

cat-posts.php in Category Posts Block 2.3, at cat-posts.php

149 lines 5.1 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Category Posts Widget
4 Plugin URI: http://jameslao.com/2009/07/29/category-posts-widget-2-0/
5 Description: Adds a widget that can display a specified number of posts from a single category. Can also set how many widgets to show.
6 Author: James Lao
7 Version: 2.3
8 Author URI: http://jameslao.com/
9 */
10
11 class CategoryPosts extends WP_Widget {
12
13 function CategoryPosts() {
14 parent::WP_Widget(false, $name='Category Posts');
15 }
16
17 /**
18 * Displays category posts widget on blog.
19 */
20 function widget($args, $instance) {
21 global $post, $wp_query;
22 extract( $args );
23
24 // If not title, use the name of the category.
25 if( !$instance["title"] ) {
26 $category_info = get_category($instance["cat"]);
27 $instance["title"] = $category_info->name;
28 }
29
30 // Get array of post info.
31 $cat_posts = new WP_Query("showposts=" . $instance["num"] . "&cat=" . $instance["cat"]);
32
33 echo $before_widget;
34
35 // Widget title
36
37 echo $before_title;
38 if( (bool) $instance["title_link"] )
39 echo '<a href="' . get_category_link($instance["cat"]) . '">' . $instance["title"] . '</a>';
40 else
41 echo $instance["title"];
42 echo $after_title;
43
44 // Post list
45 echo "<ul>\n";
46
47 while ( $cat_posts->have_posts() ) : $cat_posts->the_post();
48 ?>
49 <li class='cat-post-item'>
50
51 <?php if ( (bool) $instance["thumbnail"] && function_exists('p75HasThumbnail') && p75HasThumbnail($cat_posts->post->ID) ) { ?>
52
53 <a href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><img class='alignleft' src='<?php echo p75GetThumbnail($post->ID, $instance["thumbnail_width"], $instance["thumbnail_height"]); ?>' alt='<?php the_title_attribute(); ?>' /></a>
54
55 <?php } // end thumbnail function check ?>
56
57 <a class="post-title" href="<?php the_permalink(); ?>" title="<?php the_title_attribute(); ?>"><?php the_title(); ?></a>
58
59 <?php if ( $instance['excerpt'] ) the_excerpt(); ?>
60 </li>
61 <?php
62 endwhile;
63
64 echo "</ul>\n";
65
66 echo $after_widget;
67 }
68
69 /**
70 * Form processing... Dead simple.
71 */
72 function update($new_instance, $old_instance) {
73 $new_instance["cat"] = absint( $new_instance["cat"] );
74 $new_instance["exclude"] = (bool) $new_instance["exclude"];
75
76 return $new_instance;
77 }
78
79 /**
80 * The configuration form.
81 */
82 function form($instance) {
83 ?>
84 <p>
85 <label for="<?php echo $this->get_field_id("title"); ?>">
86 <?php _e( 'Title' ); ?>:
87 <input class="widefat" id="<?php echo $this->get_field_id("title"); ?>" name="<?php echo $this->get_field_name("title"); ?>" type="text" value="<?php echo esc_attr($instance["title"]); ?>" />
88 </label>
89 </p>
90
91 <p>
92 <label>
93 <?php _e( 'Category' ); ?>:
94 <?php wp_dropdown_categories( array( 'name' => $this->get_field_name("cat"), 'selected' => $instance["cat"] ) ); ?>
95 </label>
96 </p>
97
98 <p>
99 <label for="<?php echo $this->get_field_id("num"); ?>">
100 <?php _e('Number of posts to show'); ?>:
101 <input style="text-align: center;" id="<?php echo $this->get_field_id("num"); ?>" name="<?php echo $this->get_field_name("num"); ?>" type="text" value="<?php echo absint($instance["num"]); ?>" size='3' />
102 </label>
103 </p>
104
105 <p>
106 <label for="<?php echo $this->get_field_id("title_link"); ?>">
107 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("title_link"); ?>" name="<?php echo $this->get_field_name("title_link"); ?>"<?php checked( (bool) $instance["title_link"], true ); ?> />
108 <?php _e( 'Make widget title link' ); ?>
109 </label>
110 </p>
111
112 <p>
113 <label for="<?php echo $this->get_field_id("excerpt"); ?>">
114 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("excerpt"); ?>" name="<?php echo $this->get_field_name("excerpt"); ?>"<?php checked( (bool) $instance["excerpt"], true ); ?> />
115 <?php _e( 'Show post excerpt' ); ?>
116 </label>
117 </p>
118
119 <?php if ( function_exists("p75GetThumbnail") ) : ?>
120 <p>
121 <label for="<?php echo $this->get_field_id("thumbnail"); ?>">
122 <input type="checkbox" class="checkbox" id="<?php echo $this->get_field_id("thumbnail"); ?>" name="<?php echo $this->get_field_name("thumbnail"); ?>"<?php checked( (bool) $instance["thumbnail"], true ); ?> />
123 <?php _e( 'Show post thumbnail' ); ?>
124 </label>
125 </p>
126 <p>
127 <label>
128 <?php _e('Thumbnail dimensions'); ?>:<br />
129 <label for="<?php echo $this->get_field_id("thumbnail_width"); ?>">
130 W: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id("thumbnail_width"); ?>" name="<?php echo $this->get_field_name("thumbnail_width"); ?>" value="<?php echo $instance["thumbnail_width"]; ?>" />
131 </label>
132
133 <label for="<?php echo $this->get_field_id("thumbnail_height"); ?>">
134 H: <input class="widefat" style="width:40%;" type="text" id="<?php echo $this->get_field_id("thumbnail_height"); ?>" name="<?php echo $this->get_field_name("thumbnail_height"); ?>" value="<?php echo $instance["thumbnail_height"]; ?>" />
135 </label>
136 </label>
137 </p>
138 <?php endif; ?>
139
140 <?php
141
142 }
143
144 }
145
146 add_action( 'widgets_init', create_function('', 'return register_widget("CategoryPosts");') );
147
148 ?>
149