Advanced Random Posts Widget - Version 1.0

Version Description

  • 10/2/2013 =
  • Initial release
Download this release

Release Info

Developer satrya
Plugin Icon 128x128 Advanced Random Posts Widget
Version 1.0
Comparing to
See all releases

Version 1.0

arpw.css ADDED
@@ -0,0 +1,66 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ /*
2
+ Description: Custom CSS for the Advanced Random Posts Widget.
3
+ Version: 1.0
4
+ Author: Satrya
5
+ License: GPLv2
6
+ */
7
+
8
+ .arpw-block ul {
9
+ list-style: none !important;
10
+ margin-left: 0 !important;
11
+ padding-left: 0 !important;
12
+ }
13
+
14
+ .arpw-block li {
15
+ border-bottom: 1px solid #eee;
16
+ margin-bottom: 10px;
17
+ padding-bottom: 10px;
18
+ }
19
+
20
+ .arpw-block a {
21
+ text-decoration: none;
22
+ }
23
+
24
+ .arpw-block h3 {
25
+ background: none !important;
26
+ clear: none;
27
+ margin-bottom: 0 !important;
28
+ font-weight: normal;
29
+ font-size: 12px !important;
30
+ font-family: Arial, sans-serif;
31
+ line-height: 1.5em;
32
+ }
33
+
34
+ .arpw-alignleft {
35
+ border: 1px solid #EEE !important;
36
+ box-shadow: none !important;
37
+ display: inline;
38
+ float: left;
39
+ margin: 2px 10px 0 0;
40
+ padding: 3px !important;
41
+ }
42
+
43
+ .arpw-summary {
44
+ font-family: Arial, sans-serif;
45
+ font-size: 12px;
46
+ }
47
+
48
+ .arpw-time {
49
+ color: #bbb;
50
+ font-size: 11px;
51
+ font-family: Arial, sans-serif;
52
+ }
53
+
54
+ .arpw-clearfix:before,
55
+ .arpw-clearfix:after {
56
+ content: "";
57
+ display: table;
58
+ }
59
+
60
+ .arpw-clearfix:after {
61
+ clear: both;
62
+ }
63
+
64
+ .arpw-clearfix {
65
+ *zoom: 1;
66
+ }
arpw.php ADDED
@@ -0,0 +1,93 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Advanced Random Posts Widget
4
+ Plugin URI: https://github.com/themephe/advanced-random-posts-widget
5
+ Description: Enables advanced random posts widget.
6
+ Version: 1.0
7
+ Author: Satrya
8
+ Author URI: http://satrya.me
9
+ Author Email: satrya@satrya.me
10
+ License: GPLv2
11
+ */
12
+
13
+ // Exit if accessed directly
14
+ if ( ! defined( 'ABSPATH' ) ) exit;
15
+
16
+ if ( ! class_exists( 'ARP_Widget' ) ) :
17
+
18
+ class ARP_Widget {
19
+
20
+ /**
21
+ * PHP5 constructor method.
22
+ *
23
+ * @since 1.0
24
+ */
25
+ public function __construct() {
26
+
27
+ add_action( 'plugins_loaded', array( &$this, 'constants' ), 1 );
28
+
29
+ add_action( 'plugins_loaded', array( &$this, 'i18n' ), 2 );
30
+
31
+ add_action( 'plugins_loaded', array( &$this, 'includes' ), 3 );
32
+
33
+ add_action( 'init', array( &$this, 'init' ) );
34
+
35
+ }
36
+
37
+ /**
38
+ * Defines constants used by the plugin.
39
+ *
40
+ * @since 1.0
41
+ */
42
+ public function constants() {
43
+
44
+ define( 'ARPW_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
45
+
46
+ define( 'ARPW_URI', trailingslashit( plugin_dir_url( __FILE__ ) ) );
47
+
48
+ define( 'ARPW_INCLUDES', ARPW_DIR . trailingslashit( 'includes' ) );
49
+
50
+ }
51
+
52
+ /**
53
+ * Loads the translation files.
54
+ *
55
+ * @since 1.0
56
+ */
57
+ public function i18n() {
58
+
59
+ /* Load the translation of the plugin. */
60
+ load_plugin_textdomain( 'arpw', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
61
+
62
+ }
63
+
64
+ /**
65
+ * Loads the initial files needed by the plugin.
66
+ *
67
+ * @since 1.0
68
+ */
69
+ public function includes() {
70
+
71
+ require_once( ARPW_INCLUDES . 'widget-advanced-random-posts.php' );
72
+ }
73
+
74
+ /**
75
+ * Register custom style for the widget.
76
+ *
77
+ * @since 1.0
78
+ */
79
+ function init() {
80
+
81
+ if( ! is_admin() ) {
82
+
83
+ wp_enqueue_style( 'arpw-style', ARPW_URI . 'arpw.css' );
84
+
85
+ }
86
+
87
+ }
88
+
89
+ }
90
+
91
+ new ARP_Widget;
92
+ endif;
93
+ ?>
includes/widget-advanced-random-posts.php ADDED
@@ -0,0 +1,247 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+
3
+ // Exit if accessed directly
4
+ if ( ! defined('ABSPATH') ) exit;
5
+
6
+ class arpw_widget extends WP_Widget {
7
+
8
+ /**
9
+ * Widget setup
10
+ */
11
+ function arpw_widget() {
12
+
13
+ $widget_ops = array(
14
+ 'classname' => 'arpw_widget',
15
+ 'description' => __( 'Enable advanced random posts widget.', 'arpw' )
16
+ );
17
+
18
+ $control_ops = array(
19
+ 'width' => 300,
20
+ 'height' => 350,
21
+ 'id_base' => 'arpw_widget'
22
+ );
23
+
24
+ $this->WP_Widget( 'arpw_widget', __( 'Advanced Random Posts', 'arpw' ), $widget_ops, $control_ops );
25
+
26
+ }
27
+
28
+ /**
29
+ * Display widget
30
+ */
31
+ function widget( $args, $instance ) {
32
+ extract( $args, EXTR_SKIP );
33
+
34
+ $title = apply_filters( 'widget_title', $instance['title'] );
35
+ $limit = $instance['limit'];
36
+ $excerpt = $instance['excerpt'];
37
+ $length = (int)( $instance['length'] );
38
+ $thumb = $instance['thumb'];
39
+ $thumb_height = (int)( $instance['thumb_height'] );
40
+ $thumb_width = (int)( $instance['thumb_width'] );
41
+ $cat = $instance['cat'];
42
+ $date = $instance['date'];
43
+
44
+ echo $before_widget;
45
+
46
+ if (!empty( $title ))
47
+ echo $before_title . $title . $after_title;
48
+
49
+ global $post;
50
+
51
+ $args = array(
52
+ 'numberposts' => $limit,
53
+ 'cat' => $cat,
54
+ 'post_type' => 'post',
55
+ 'orderby' => 'rand'
56
+ );
57
+
58
+ $arpwwidget = get_posts( $args );
59
+
60
+ ?>
61
+
62
+ <div class="arpw-block">
63
+
64
+ <ul>
65
+
66
+ <?php foreach( $arpwwidget as $post ) : setup_postdata( $post ); ?>
67
+
68
+ <li class="arpw-clearfix">
69
+
70
+ <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'arpw' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark">
71
+
72
+ <?php
73
+ if( $thumb == true ) {
74
+
75
+ if ( current_theme_supports( 'get-the-image' ) )
76
+ get_the_image( array( 'meta_key' => 'Thumbnail', 'height' => $thumb_height, 'width' => $thumb_width, 'image_class' => 'arpw-alignleft' ) );
77
+ else
78
+ the_post_thumbnail( array( $thumb_height, $thumb_width ), array( 'class' => 'arpw-alignleft', 'alt' => esc_attr( get_the_title() ), 'title' => esc_attr( get_the_title() ) ) );
79
+
80
+ }
81
+ ?>
82
+
83
+ </a>
84
+
85
+ <h3 class="arpw-title">
86
+ <a href="<?php the_permalink(); ?>" title="<?php printf( esc_attr__( 'Permalink to %s', 'arpw' ), the_title_attribute( 'echo=0' ) ); ?>" rel="bookmark"><?php the_title(); ?></a>
87
+ </h3>
88
+
89
+ <?php if( $date == true ) { ?>
90
+ <span class="arpw-time"><?php echo human_time_diff( get_the_time( 'U' ), current_time( 'timestamp' ) ) . __( ' ago', 'arpw' ); ?></span>
91
+ <?php } ?>
92
+
93
+ <?php if( $excerpt == true ) { ?>
94
+ <div class="arpw-summary"><?php echo arpw_excerpt( $length ); ?></div>
95
+ <?php } ?>
96
+
97
+ </li>
98
+
99
+ <?php endforeach; wp_reset_postdata(); ?>
100
+
101
+ </ul>
102
+
103
+ </div><!-- .arpw-block -->
104
+
105
+ <?php
106
+
107
+ echo $after_widget;
108
+
109
+ }
110
+
111
+ /**
112
+ * Update widget
113
+ */
114
+ function update( $new_instance, $old_instance ) {
115
+
116
+ $instance = $old_instance;
117
+ $instance['title'] = esc_attr( $new_instance['title'] );
118
+ $instance['limit'] = $new_instance['limit'];
119
+ $instance['excerpt'] = $new_instance['excerpt'];
120
+ $instance['length'] = (int)( $new_instance['length'] );
121
+ $instance['thumb'] = $new_instance['thumb'];
122
+ $instance['thumb_height'] = (int)( $new_instance['thumb_height'] );
123
+ $instance['thumb_width'] = (int)( $new_instance['thumb_width'] );
124
+ $instance['cat'] = $new_instance['cat'];
125
+ $instance['date'] = $new_instance['date'];
126
+
127
+ return $instance;
128
+
129
+ }
130
+
131
+ /**
132
+ * Widget setting
133
+ */
134
+ function form( $instance ) {
135
+
136
+ /* Set up some default widget settings. */
137
+ $defaults = array(
138
+ 'title' => '',
139
+ 'limit' => 5,
140
+ 'excerpt' => '',
141
+ 'length' => 10,
142
+ 'thumb' => true,
143
+ 'thumb_height' => 45,
144
+ 'thumb_width' => 45,
145
+ 'cat' => '',
146
+ 'date' => true
147
+ );
148
+
149
+ $instance = wp_parse_args( (array) $instance, $defaults );
150
+ $title = esc_attr( $instance['title'] );
151
+ $limit = $instance['limit'];
152
+ $excerpt = $instance['excerpt'];
153
+ $length = (int)($instance['length']);
154
+ $thumb = $instance['thumb'];
155
+ $thumb_height = (int)( $instance['thumb_height'] );
156
+ $thumb_width = (int)( $instance['thumb_width'] );
157
+ $cat = $instance['cat'];
158
+ $date = $instance['date'];
159
+
160
+ ?>
161
+
162
+ <p>
163
+ <label for="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>"><?php _e( 'Title:', 'arpw' ); ?></label>
164
+ <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'title' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'title' ) ); ?>" type="text" value="<?php echo $title; ?>" />
165
+ </p>
166
+ <p>
167
+ <label for="<?php echo esc_attr( $this->get_field_id( 'limit' ) ); ?>"><?php _e( 'Limit:', 'arpw' ); ?></label>
168
+ <select class="widefat" name="<?php echo $this->get_field_name( 'limit' ); ?>" id="<?php echo $this->get_field_id( 'limit' ); ?>">
169
+ <?php for ( $i=1; $i<=20; $i++ ) { ?>
170
+ <option <?php selected( $limit, $i ) ?> value="<?php echo $i; ?>"><?php echo $i; ?></option>
171
+ <?php } ?>
172
+ </select>
173
+ </p>
174
+ <p>
175
+ <label for="<?php echo esc_attr( $this->get_field_id( 'date' ) ); ?>"><?php _e( 'Display date?', 'arpw' ); ?></label>
176
+ <input id="<?php echo $this->get_field_id( 'date' ); ?>" name="<?php echo $this->get_field_name( 'date' ); ?>" type="checkbox" value="1" <?php checked( '1', $date ); ?> />&nbsp;
177
+ </p>
178
+ <p>
179
+ <label for="<?php echo esc_attr( $this->get_field_id( 'excerpt' ) ); ?>"><?php _e( 'Display excerpt?', 'arpw' ); ?></label>
180
+ <input id="<?php echo $this->get_field_id( 'excerpt' ); ?>" name="<?php echo $this->get_field_name( 'excerpt' ); ?>" type="checkbox" value="1" <?php checked( '1', $excerpt ); ?> />&nbsp;
181
+ </p>
182
+ <p>
183
+ <label for="<?php echo esc_attr( $this->get_field_id( 'length' ) ); ?>"><?php _e( 'Excerpt length:', 'arpw' ); ?></label>
184
+ <input class="widefat" id="<?php echo esc_attr( $this->get_field_id( 'length' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'length' ) ); ?>" type="text" value="<?php echo $length; ?>" />
185
+ </p>
186
+
187
+ <?php if( current_theme_supports( 'post-thumbnails' ) ) { ?>
188
+
189
+ <p>
190
+ <label for="<?php echo esc_attr( $this->get_field_id( 'thumb' ) ); ?>"><?php _e( 'Display thumbnail?', 'arpw' ); ?></label>
191
+ <input id="<?php echo $this->get_field_id( 'thumb' ); ?>" name="<?php echo $this->get_field_name( 'thumb' ); ?>" type="checkbox" value="1" <?php checked( '1', $thumb ); ?> />&nbsp;
192
+ </p>
193
+ <p>
194
+ <label for="<?php echo esc_attr( $this->get_field_id( 'thumb_height' ) ); ?>"><?php _e( 'Thumbnail size (height x width):', 'arpw' ); ?></label>
195
+ <input id="<?php echo esc_attr( $this->get_field_id( 'thumb_height' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'thumb_height' ) ); ?>" type="text" value="<?php echo $thumb_height; ?>" />
196
+ <input id="<?php echo esc_attr( $this->get_field_id( 'thumb_width' ) ); ?>" name="<?php echo esc_attr( $this->get_field_name( 'thumb_width' ) ); ?>" type="text" value="<?php echo $thumb_width; ?>" />
197
+ </p>
198
+
199
+ <?php } ?>
200
+
201
+ <p>
202
+ <label for="<?php echo esc_attr( $this->get_field_id( 'cat' ) ); ?>"><?php _e( 'Limit to category: ' , 'arpw' ); ?></label>
203
+ <?php wp_dropdown_categories( array( 'name' => $this->get_field_name( 'cat' ), 'show_option_all' => __( 'All categories' , 'arpw' ), 'hide_empty' => 1, 'hierarchical' => 1, 'selected' => $cat ) ); ?>
204
+ </p>
205
+ <p>
206
+ <span style="color: #f00;"><?php printf( __( 'Advanced Random Posts Widget is a project by <a href="%s" target="_blank">Satrya</a>', 'arpw' ), esc_url( 'http://satrya.me' ) ); ?></span>
207
+ </p>
208
+
209
+ <?php
210
+ }
211
+
212
+ }
213
+
214
+ /**
215
+ * Register widget.
216
+ *
217
+ * @since 1.0
218
+ */
219
+ add_action( 'widgets_init', 'arpw_register_widget' );
220
+ function arpw_register_widget() {
221
+
222
+ register_widget( 'arpw_widget' );
223
+
224
+ }
225
+
226
+ /**
227
+ * Print a custom excerpt.
228
+ * http://bavotasan.com/2009/limiting-the-number-of-words-in-your-excerpt-or-content-in-wordpress/
229
+ *
230
+ * @since 1.0
231
+ */
232
+ function arpw_excerpt( $length ) {
233
+
234
+ $excerpt = explode( ' ', get_the_excerpt(), $length );
235
+ if ( count( $excerpt )>=$length ) {
236
+ array_pop( $excerpt );
237
+ $excerpt = implode( " ", $excerpt ) . '&hellip;';
238
+ } else {
239
+ $excerpt = implode( " ", $excerpt );
240
+ }
241
+ $excerpt = preg_replace( '`\[[^\]]*\]`', '', $excerpt );
242
+
243
+ return $excerpt;
244
+
245
+ }
246
+
247
+ ?>
languages/arpw.mo ADDED
Binary file
languages/arpw.po ADDED
@@ -0,0 +1,78 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ msgid ""
2
+ msgstr ""
3
+ "Project-Id-Version: Advanced Random Posts Widget\n"
4
+ "POT-Creation-Date: 2013-02-10 01:48+0700\n"
5
+ "PO-Revision-Date: 2013-02-10 01:48+0700\n"
6
+ "Last-Translator: M.Satrya <satrya@tokokoo.com>\n"
7
+ "Language-Team: Satrya <satrya@satrya.me>\n"
8
+ "Language: English\n"
9
+ "MIME-Version: 1.0\n"
10
+ "Content-Type: text/plain; charset=UTF-8\n"
11
+ "Content-Transfer-Encoding: 8bit\n"
12
+ "X-Generator: Poedit 1.5.5\n"
13
+ "X-Poedit-KeywordsList: __;_e;esc_attr__;esc_attr_e\n"
14
+ "X-Poedit-Basepath: .\n"
15
+ "Plural-Forms: nplurals=2; plural=n != 1;\n"
16
+ "X-Poedit-SourceCharset: UTF-8\n"
17
+ "X-Poedit-SearchPath-0: ..\n"
18
+
19
+ #: ../includes/widget-advanced-random-posts.php:15
20
+ msgid "Enable advanced random posts widget."
21
+ msgstr ""
22
+
23
+ #: ../includes/widget-advanced-random-posts.php:24
24
+ msgid "Advanced Random Posts"
25
+ msgstr ""
26
+
27
+ #: ../includes/widget-advanced-random-posts.php:70
28
+ #: ../includes/widget-advanced-random-posts.php:86
29
+ #, php-format
30
+ msgid "Permalink to %s"
31
+ msgstr ""
32
+
33
+ #: ../includes/widget-advanced-random-posts.php:90
34
+ msgid " ago"
35
+ msgstr ""
36
+
37
+ #: ../includes/widget-advanced-random-posts.php:163
38
+ msgid "Title:"
39
+ msgstr ""
40
+
41
+ #: ../includes/widget-advanced-random-posts.php:167
42
+ msgid "Limit:"
43
+ msgstr ""
44
+
45
+ #: ../includes/widget-advanced-random-posts.php:175
46
+ msgid "Display date?"
47
+ msgstr ""
48
+
49
+ #: ../includes/widget-advanced-random-posts.php:179
50
+ msgid "Display excerpt?"
51
+ msgstr ""
52
+
53
+ #: ../includes/widget-advanced-random-posts.php:183
54
+ msgid "Excerpt length:"
55
+ msgstr ""
56
+
57
+ #: ../includes/widget-advanced-random-posts.php:190
58
+ msgid "Display thumbnail?"
59
+ msgstr ""
60
+
61
+ #: ../includes/widget-advanced-random-posts.php:194
62
+ msgid "Thumbnail size (height x width):"
63
+ msgstr ""
64
+
65
+ #: ../includes/widget-advanced-random-posts.php:202
66
+ msgid "Limit to category: "
67
+ msgstr ""
68
+
69
+ #: ../includes/widget-advanced-random-posts.php:203
70
+ msgid "All categories"
71
+ msgstr ""
72
+
73
+ #: ../includes/widget-advanced-random-posts.php:206
74
+ #, php-format
75
+ msgid ""
76
+ "Advanced Random Posts Widget is a project by <a href=\"%s\" target=\"_blank"
77
+ "\">Satrya</a>"
78
+ msgstr ""
readme.txt ADDED
@@ -0,0 +1,43 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ === Plugin Name ===
2
+ Contributors: satrya
3
+ Tags: random posts, random, thumbnails, widget, widgets, sidebar, excerpt, multiple widgets
4
+ Requires at least: 3.4
5
+ Tested up to: 3.5
6
+ Stable tag: 1.0
7
+ License: GPLv2 or later
8
+ License URI: http://www.gnu.org/licenses/gpl-2.0.html
9
+
10
+ Easily display random posts in a widget. Allows you to display them with thumbnails, post excerpt, specific category and more.
11
+
12
+ == Description ==
13
+
14
+ This plugin will enable a custom, fleksible and advanced random posts widget. Allows you to display a list of random posts with thumbnail and excerpt also you can display it from all or a specific category.
15
+
16
+ = Features Include: =
17
+
18
+ * Display thumbnails, with customizable size.
19
+ * Display excerpt, with customizable length.
20
+ * Display from all or a specific category.
21
+ * Display post date.
22
+ * Support `get_the_image` function.
23
+ * Multiple widgets.
24
+
25
+ = Ugly Image Sizes =
26
+ This plugin creates custom image sizes. If you use images that were uploaded to the media library before you installed this plugin, please install [Regenerate Thumbnails](http://wordpress.org/extend/plugins/regenerate-thumbnails/) plugin to corrected the sizes.
27
+
28
+ = Support: =
29
+ *. [Open issue on github](https://github.com/themephe/advanced-random-posts-widget/issues).
30
+
31
+ == Installation ==
32
+
33
+ 1. Upload the 'advanced-random-posts-widget' folder to the `/wp-content/plugins/` directory
34
+ 2. Activate the plugin through the 'Plugins' menu in WordPress
35
+ 3. Go to the widgets page.
36
+
37
+ == Screenshots ==
38
+ 1. The widget settings
39
+
40
+ == Changelog ==
41
+
42
+ = 1.0 - 10/2/2013 =
43
+ * Initial release
screenshot-1.png ADDED
Binary file