Flexible Posts Widget - Version 1.0.3

Version Description

  • Fixed PHP notices that showed in the admin when WP_DEBUG is enabled
  • Added some stub code for future admin JavaScripts (not active yet).
  • Readme.txt updates
Download this release

Release Info

Developer dpe415
Plugin Icon wp plugin Flexible Posts Widget
Version 1.0.3
Comparing to
See all releases

Code changes from version 1.0.2 to 1.0.3

flexible-posts-widget.js ADDED
@@ -0,0 +1,8 @@
 
 
 
 
 
 
 
 
1
+ /*
2
+ * Flexible Posts Widget
3
+ * Admin Scripts
4
+ * Author: dpe415
5
+ * URI: http://wordpress.org/extend/plugins/flexible-posts-widget/
6
+ */
7
+
8
+ // Nothing here yet...
flexible-posts-widget.php CHANGED
@@ -2,9 +2,9 @@
2
  /*
3
  Plugin Name: Flexible Posts Widget
4
  Plugin URI: http://wordpress.org/extend/plugins/flexible-posts-widget/
5
- Author: David Paul Ellenwood
6
  Author URI: http://dpedesign.com
7
- Version: 1.0.2
8
  Description: An advanced posts display widget with many options: post by taxonomy & term or post type, thumbnails, order & order by, customizable templates
9
  */
10
 
@@ -25,22 +25,30 @@ class DPE_Flexible_Posts_Widget extends WP_Widget {
25
 
26
  /** constructor */
27
  function DPE_Flexible_Posts_Widget() {
28
- parent::WP_Widget(false, $name = 'Flexible Posts Widget');
 
 
 
 
 
 
 
 
 
 
29
  }
30
 
 
 
 
 
 
 
31
  /** @see WP_Widget::widget */
32
  function widget($args, $instance) {
33
  extract( $args );
34
- $title = apply_filters('widget_title', $instance['title']);
35
- $taxonomy = esc_attr( $instance['taxonomy'] );
36
- $term = esc_attr( $instance['term'] );
37
- $number = esc_attr( (int)$instance['number'] );
38
- $thumb_size = esc_attr( $instance['thumb_size'] );
39
- $thumbnail = esc_attr( $instance['thumbnail'] );
40
- $posttype = esc_attr( $instance['posttype'] );
41
- $orderby = esc_attr( $instance['orderby'] );
42
- $order = esc_attr( $instance['order'] );
43
- $template = esc_attr( $instance['template'] );
44
 
45
  if( empty($template) )
46
  $template = 'widget';
@@ -73,8 +81,10 @@ class DPE_Flexible_Posts_Widget extends WP_Widget {
73
  // Get the posts for this instance
74
  $flexible_posts = new WP_Query( $args );
75
 
 
76
  include( $this->getTemplateHierarchy( $template ) );
77
 
 
78
  wp_reset_postdata();
79
 
80
  }
@@ -84,14 +94,14 @@ class DPE_Flexible_Posts_Widget extends WP_Widget {
84
  global $posttypes;
85
  $instance = $old_instance;
86
  $instance['title'] = strip_tags( $new_instance['title'] );
 
87
  $instance['taxonomy'] = $new_instance['taxonomy'];
88
  $instance['term'] = strip_tags( $new_instance['term'] );
89
  $instance['number'] = strip_tags( $new_instance['number'] );
90
- $instance['thumb_size'] = $new_instance['thumb_size'];
91
- $instance['thumbnail'] = $new_instance['thumbnail'];
92
- $instance['posttype'] = $new_instance['posttype'];
93
  $instance['orderby'] = $new_instance['orderby'];
94
  $instance['order'] = $new_instance['order'];
 
 
95
  $instance['template'] = strip_tags( $new_instance['template'] );
96
  return $instance;
97
  }
@@ -101,43 +111,24 @@ class DPE_Flexible_Posts_Widget extends WP_Widget {
101
 
102
  $posttypes = get_post_types('', 'objects');
103
  $taxonomies = get_taxonomies('', 'objects');
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
104
 
105
- $orderbys = array(
106
- 'ID',
107
- 'title',
108
- 'date',
109
- 'rand',
110
- 'menu_order',
111
- );
112
-
113
- $orders = array(
114
- 'ASC',
115
- 'DESC',
116
- );
117
-
118
- $thumb_sizes = get_intermediate_image_sizes();
119
-
120
- if( !empty($instance) ) {
121
- $title = esc_attr ($instance['title'] );
122
- $taxonomy = esc_attr( $instance['taxonomy'] );
123
- $term = esc_attr( $instance['term'] );
124
- $number = esc_attr( $instance['number'] );
125
- $thumb_size = esc_attr( $instance['thumb_size'] );
126
- $thumbnail = esc_attr( $instance['thumbnail'] );
127
- $posttype = esc_attr( $instance['posttype'] );
128
- $orderby = esc_attr( $instance['orderby'] );
129
- $order = esc_attr( $instance['order'] );
130
- $template = esc_attr( $instance['template'] );
131
- }
132
-
133
- if( empty($orderby) )
134
- $orderby = 'date';
135
-
136
- if( empty($order) )
137
- $order = 'DESC';
138
-
139
- if( empty($template) )
140
- $template = 'widget';
141
 
142
  ?>
143
  <p>
@@ -188,7 +179,7 @@ class DPE_Flexible_Posts_Widget extends WP_Widget {
188
  <select class="widefat" name="<?php echo $this->get_field_name('thumb_size'); ?>" id="<?php echo $this->get_field_id('thumb_size'); ?>">
189
  <?php
190
  foreach ($thumb_sizes as $option) {
191
- echo '<option value="' . $option . '" id="' . $option . '"', $thumb_size == $option ? ' selected="selected"' : '', '>', $option, '</option>';
192
  }
193
  ?>
194
  </select>
2
  /*
3
  Plugin Name: Flexible Posts Widget
4
  Plugin URI: http://wordpress.org/extend/plugins/flexible-posts-widget/
5
+ Author: dpe415
6
  Author URI: http://dpedesign.com
7
+ Version: 1.0.3
8
  Description: An advanced posts display widget with many options: post by taxonomy & term or post type, thumbnails, order & order by, customizable templates
9
  */
10
 
25
 
26
  /** constructor */
27
  function DPE_Flexible_Posts_Widget() {
28
+
29
+ parent::WP_Widget(false, $name = 'Flexible Posts Widget');
30
+ //$this->register_sns();
31
+ /*
32
+ global $pagenow;
33
+ if (defined("WP_ADMIN") && WP_ADMIN) {
34
+ if ( 'widgets.php' == $pagenow ) {
35
+ wp_enqueue_script( 'dpe-flexible-posts-widget' );
36
+ }
37
+ }
38
+ */
39
  }
40
 
41
+ function register_sns() {
42
+ $dir = plugins_url('/', __FILE__);
43
+ wp_register_script( 'dpe-flexible-posts-widget', $dir . 'flexible-posts-widget.js', array('jquery','thickbox'), false, true );
44
+ }
45
+
46
+
47
  /** @see WP_Widget::widget */
48
  function widget($args, $instance) {
49
  extract( $args );
50
+ extract( $instance );
51
+ $title = apply_filters( 'widget_title', empty( $title ) ? '' : $title );
 
 
 
 
 
 
 
 
52
 
53
  if( empty($template) )
54
  $template = 'widget';
81
  // Get the posts for this instance
82
  $flexible_posts = new WP_Query( $args );
83
 
84
+ // Get and include the template we're going to use
85
  include( $this->getTemplateHierarchy( $template ) );
86
 
87
+ // Be sure to reset any post_data before proceeding
88
  wp_reset_postdata();
89
 
90
  }
94
  global $posttypes;
95
  $instance = $old_instance;
96
  $instance['title'] = strip_tags( $new_instance['title'] );
97
+ $instance['posttype'] = $new_instance['posttype'];
98
  $instance['taxonomy'] = $new_instance['taxonomy'];
99
  $instance['term'] = strip_tags( $new_instance['term'] );
100
  $instance['number'] = strip_tags( $new_instance['number'] );
 
 
 
101
  $instance['orderby'] = $new_instance['orderby'];
102
  $instance['order'] = $new_instance['order'];
103
+ $instance['thumb_size'] = $new_instance['thumb_size'];
104
+ $instance['thumbnail'] = $new_instance['thumbnail'];
105
  $instance['template'] = strip_tags( $new_instance['template'] );
106
  return $instance;
107
  }
111
 
112
  $posttypes = get_post_types('', 'objects');
113
  $taxonomies = get_taxonomies('', 'objects');
114
+ $orderbys = array( 'ID', 'title', 'date', 'rand', 'menu_order', );
115
+ $orders = array( 'ASC', 'DESC', );
116
+ $thumb_sizes = get_intermediate_image_sizes();
117
+
118
+ $instance = wp_parse_args( (array) $instance, array(
119
+ 'title' => '',
120
+ 'posttype' => 'post',
121
+ 'taxonomy' => '',
122
+ 'term' => '',
123
+ 'number' => '',
124
+ 'orderby' => 'date',
125
+ 'order' => 'DESC',
126
+ 'thumbnail' => false,
127
+ 'thumbsize' => '',
128
+ 'template' => 'widget',
129
+ ) );
130
 
131
+ extract( $instance );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
132
 
133
  ?>
134
  <p>
179
  <select class="widefat" name="<?php echo $this->get_field_name('thumb_size'); ?>" id="<?php echo $this->get_field_id('thumb_size'); ?>">
180
  <?php
181
  foreach ($thumb_sizes as $option) {
182
+ echo '<option value="' . $option . '" id="' . $option . '"', $thumbsize == $option ? ' selected="selected"' : '', '>', $option, '</option>';
183
  }
184
  ?>
185
  </select>
readme.txt CHANGED
@@ -1,34 +1,31 @@
1
  === Flexible Posts Widget ===
2
- Contributors: David Paul Ellenwood
3
- Donate link:
4
  Tags: widget, widgets, posts, recent posts, thumbnails, custom post types, custom taxonomies
5
  Requires at least: 3.2
6
- Tested up to: 3.3.1
7
- Stable tag: 1.0.2
8
 
9
- An advanced posts display widget with many options: post by taxonomy & term or post type, thumbnails, order & order by, customizable templates
10
 
11
  == Description ==
12
 
13
- The default WordPress Recent Posts widget is exceptionally basic. Flexible Posts Widget extends this widget with many per-widget customizable options.
14
-
15
- Flexible Posts Widget was born as I found myself always needing a simple way to display a selection of posts from any taxonomy or post type as a list of "Recent" or "Related" posts.
16
 
17
  = Features & options =
18
 
19
  * Customizable widget title
20
- * Get posts by either a taxonomy & term *OR* by any available post type.
21
  * Control the number of posts displayed.
22
  * Option to display the post thumbnail (feature image).
23
- * Selectable post thumbnail size from available image sizes.
24
- * Selectable sort order by (Date, ID, Title, Menu Order, Random) and order (ASC, DESC).
25
  * The widget's HTML output can be customized by user-defined templates located in the current theme folder.
26
- * Currently, no added CSS or JavaScripts added to your site. Style the widget how ever you'd like!
27
 
28
 
29
  == Installation ==
30
 
31
- 1. Upload the 'fleible-posts-widget' folder to the `/wp-content/plugins/` directory.
32
  1. Activate the plugin through the 'Plugins' menu in WordPress.
33
  1. Go to 'Appearance' > 'Widgets' and place the widget into a sidebar to begin configuring it.
34
 
@@ -36,9 +33,21 @@ Flexible Posts Widget was born as I found myself always needing a simple way to
36
 
37
  1. Create a folder called `flexible-posts-widget` in the root of your theme folder.
38
  1. Copy `widget.php` from within this plugin's `views` folder into your theme's new `flexible-posts-widget` folder.
39
- 1. Optional: Rename your theme's `widget.php` template file to a more descriptive name of your choice.
40
- 1. Go to 'Appearance' > 'Widgets' page in WordPress and configure a new Flexible Posts Widget
41
- 1. Enter the name of the template file you added to your theme *without* the .php extension in the 'Template Filename' field.
 
 
 
 
 
 
 
 
 
 
 
 
42
 
43
 
44
  == Other Notes ==
@@ -49,31 +58,23 @@ Flexible Posts Widget comes with a default template for the widget output. If yo
49
 
50
  Edit the new file in your theme to your desired HTML layout. Please do not edit the one in the plugin folder as that will cause conflicts when you update the plugin to the latest release.
51
 
52
- = Wish List =
53
-
54
- Plugin updates & future features list
55
 
56
- * Fix debug notices for undefined indexes on widgets admin screen.
57
  * Dynamically populate available terms based on a selected taxonomy.
58
  * Make the "Get Posts By" section selectable and only show the chosen method: Taxonomy & Term or Post Type.
59
  * Dynamically populate the "Template Filename" field based on the templates available.
60
  * Add default styles for the widget display & an option to load or not load them (?)
61
 
62
 
63
- == Frequently Asked Questions ==
64
-
65
- = Questions, Support & Bug Reports =
66
- To get answers to your questions, request help or submit a bug report, please visit the forum: http://wordpress.org/tags/flexible-posts-widget/
67
-
68
-
69
- == Screenshots ==
70
-
71
- 1. Flexible Posts Widget admin screen.
72
- 1. Example Flexible Posts Widget showing the post thumbnail and title wrapped in a link to the post.
73
-
74
 
 
 
 
 
75
 
76
- == Changelog ==
 
77
 
78
  = 1.0 =
79
  * First public release
1
  === Flexible Posts Widget ===
2
+ Contributors: dpe415
3
+ Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=DJKSKHJWYAWDU
4
  Tags: widget, widgets, posts, recent posts, thumbnails, custom post types, custom taxonomies
5
  Requires at least: 3.2
6
+ Tested up to: 3.3.2
7
+ Stable tag: 1.0.3
8
 
9
+ An advanced posts display widget with many options. Display posts in your sidebars exactly the way you like!
10
 
11
  == Description ==
12
 
13
+ The default WordPress Recent Posts widget is exceptionally basic. I found myself always in need of a simple way to display a selection of posts from any taxonomy or post type in a theme sidebar; hence, Flexible Posts Widget. Flexible Posts Widget extends the default widget with many per-instance options.
 
 
14
 
15
  = Features & options =
16
 
17
  * Customizable widget title
18
+ * Get posts using either a selectable taxonomy & term *OR* by selecting any post type.
19
  * Control the number of posts displayed.
20
  * Option to display the post thumbnail (feature image).
21
+ * Select the post thumbnail size to display from available image sizes.
22
+ * Select the sort orderby: Date, ID, Title, Menu Order, Random and sort order: ASC or DESC.
23
  * The widget's HTML output can be customized by user-defined templates located in the current theme folder.
 
24
 
25
 
26
  == Installation ==
27
 
28
+ 1. Upload the `flexible-posts-widget` folder to the `/wp-content/plugins/` directory.
29
  1. Activate the plugin through the 'Plugins' menu in WordPress.
30
  1. Go to 'Appearance' > 'Widgets' and place the widget into a sidebar to begin configuring it.
31
 
33
 
34
  1. Create a folder called `flexible-posts-widget` in the root of your theme folder.
35
  1. Copy `widget.php` from within this plugin's `views` folder into your theme's new `flexible-posts-widget` folder.
36
+ 1. Optional: Rename your theme's `widget.php` template file to a name of your choice.
37
+ 1. Go to 'Appearance' > 'Widgets' in WordPress to configure an instance of the widget.
38
+ 1. In the 'Template Filename' field enter the name of the template file you added to your theme *without* the .php extension.
39
+
40
+
41
+ == Frequently Asked Questions ==
42
+
43
+ = Questions, Support & Bug Reports =
44
+ To get answers to your questions, request help or submit a bug report, please visit the forum: http://wordpress.org/tags/flexible-posts-widget/
45
+
46
+
47
+ == Screenshots ==
48
+
49
+ 1. Flexible Posts Widget admin screen.
50
+ 1. Example Flexible Posts Widget showing the post thumbnail and title wrapped in a link to the post.
51
 
52
 
53
  == Other Notes ==
58
 
59
  Edit the new file in your theme to your desired HTML layout. Please do not edit the one in the plugin folder as that will cause conflicts when you update the plugin to the latest release.
60
 
61
+ = Future updates & features list =
 
 
62
 
 
63
  * Dynamically populate available terms based on a selected taxonomy.
64
  * Make the "Get Posts By" section selectable and only show the chosen method: Taxonomy & Term or Post Type.
65
  * Dynamically populate the "Template Filename" field based on the templates available.
66
  * Add default styles for the widget display & an option to load or not load them (?)
67
 
68
 
69
+ == Changelog ==
 
 
 
 
 
 
 
 
 
 
70
 
71
+ = 1.0.3 =
72
+ * Fixed PHP notices that showed in the admin when WP_DEBUG is enabled
73
+ * Added some stub code for future admin JavaScripts (not active yet).
74
+ * Readme.txt updates
75
 
76
+ = 1.0.2 =
77
+ * Readme.txt updates
78
 
79
  = 1.0 =
80
  * First public release
screenshot-1.png CHANGED
Binary file
views/widget.php CHANGED
@@ -9,7 +9,7 @@ if ( !defined('ABSPATH') )
9
 
10
  echo $before_widget;
11
 
12
- if ( $title )
13
  echo $before_title . $title . $after_title;
14
 
15
  if( $flexible_posts->have_posts() ):
@@ -19,8 +19,8 @@ if ( $title )
19
  <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
20
  <a href="<?php echo the_permalink(); ?>">
21
  <?php
22
- if($thumbnail == true)
23
- the_post_thumbnail($thumb_size);
24
  ?>
25
  <h4 class="title"><?php the_title(); ?></h4>
26
  </a>
9
 
10
  echo $before_widget;
11
 
12
+ if ( !empty($title) )
13
  echo $before_title . $title . $after_title;
14
 
15
  if( $flexible_posts->have_posts() ):
19
  <li id="post-<?php the_ID(); ?>" <?php post_class(); ?>>
20
  <a href="<?php echo the_permalink(); ?>">
21
  <?php
22
+ if( $thumbnail == true )
23
+ the_post_thumbnail( $thumbsize );
24
  ?>
25
  <h4 class="title"><?php the_title(); ?></h4>
26
  </a>