Related Posts Thumbnails Plugin for WordPress - Version 1.1

Version Description

  • removed PHP warnings for getimagesize and file if wrong header was received
  • fixed Categories and Tags confusion (when you selected Categories relation was based on Tags and vice versa)
  • added Categories option to select specific categories
  • added post custom field name option as a source for thumbnails
Download this release

Release Info

Developer marynixie
Plugin Icon 128x128 Related Posts Thumbnails Plugin for WordPress
Version 1.1
Comparing to
See all releases

Code changes from version 1.0 to 1.1

locale/related-posts-thumbnails-ru_RU.mo CHANGED
Binary file
locale/related-posts-thumbnails-ru_RU.po CHANGED
@@ -7,7 +7,7 @@ msgstr ""
7
  "Project-Id-Version: Related Posts Thubmnails 1.0\n"
8
  "Report-Msgid-Bugs-To: \n"
9
  "POT-Creation-Date: 2010-05-19 17:17-0700\n"
10
- "PO-Revision-Date: 2010-05-19 17:38-0700\n"
11
  "Last-Translator: M.Shaldybina <mary@shaldybina.com>\n"
12
  "Language-Team: ru_RU <mary@shaldybina.com>\n"
13
  "Language: ru_RU\n"
@@ -19,27 +19,27 @@ msgstr ""
19
  "X-Poedit-Country: RUSSIA\n"
20
  "X-Poedit-SourceCharset: utf-8\n"
21
 
22
- #: related-posts-thumbnails.php:148
23
  msgid "Related Posts Thumbnails"
24
  msgstr "Миниатюры похожих записей"
25
 
26
- #: related-posts-thumbnails.php:148
27
  msgid "Related Posts Thumbs"
28
  msgstr "Похожие записи"
29
 
30
- #: related-posts-thumbnails.php:154
31
  msgid "No access"
32
  msgstr "Нет доступа"
33
 
34
- #: related-posts-thumbnails.php:170
35
  msgid "Settings updated"
36
  msgstr "Настройки обновлены"
37
 
38
- #: related-posts-thumbnails.php:182
39
  msgid "Related Posts Thumbnails Settings"
40
  msgstr "Настройки миниатюр похожих записей"
41
 
42
- #: related-posts-thumbnails.php:188
43
  msgid "General Display Options"
44
  msgstr "Общие свойства отображения"
45
 
@@ -47,86 +47,127 @@ msgstr "Общие свойства отображения"
47
  msgid "Display options"
48
  msgstr "Параметр отображения"
49
 
50
- #: related-posts-thumbnails.php:194
51
  msgid "Show on single posts only"
52
  msgstr "Показывать только на отдельной странице"
53
 
54
- #: related-posts-thumbnails.php:198
55
  msgid "Top text"
56
  msgstr "Верхний текст"
57
 
58
- #: related-posts-thumbnails.php:204
59
  msgid "Number of similar posts to display"
60
  msgstr "Количество похожих записей для отображения"
61
 
62
- #: related-posts-thumbnails.php:212
63
  msgid "Style options"
64
  msgstr "Опции стиля"
65
 
66
- #: related-posts-thumbnails.php:215
67
  msgid "Background color"
68
  msgstr "Цвет заднего фона"
69
 
70
- #: related-posts-thumbnails.php:221
71
  msgid "Background color on mouse over"
72
  msgstr "Цвет заднего фона при наведении курсора"
73
 
74
- #: related-posts-thumbnails.php:227
75
  msgid "Border color"
76
  msgstr "Цвет границы"
77
 
78
- #: related-posts-thumbnails.php:233
79
  msgid "Font color"
80
  msgstr "Цвет шрифта"
81
 
82
- #: related-posts-thumbnails.php:239
83
  msgid "Font family"
84
  msgstr "Стиль шрифта"
85
 
86
- #: related-posts-thumbnails.php:245
87
  msgid "Font size"
88
  msgstr "Размер шрифта"
89
 
90
- #: related-posts-thumbnails.php:251
91
  msgid "Text maximum length"
92
  msgstr "Максимальная длина текста"
93
 
94
- #: related-posts-thumbnails.php:259
95
  msgid "Relation Builder Options"
96
  msgstr "Настройки связей"
97
 
98
- #: related-posts-thumbnails.php:262
99
  msgid "Relation based on"
100
  msgstr "Связи расчитываются на основе"
101
 
102
- #: related-posts-thumbnails.php:265
 
103
  msgid "Categories"
104
- msgstr "Категорий"
105
 
106
- #: related-posts-thumbnails.php:267
107
  msgid "Tags"
108
- msgstr "Меток"
109
 
110
- #: related-posts-thumbnails.php:269
111
  msgid "Categories and Tags"
112
- msgstr "Категорий и меток"
113
 
114
  #: related-posts-thumbnails.php:275
115
  msgid "Thumbnails options"
116
  msgstr "Настройки миниатюр"
117
 
118
- #: related-posts-thumbnails.php:278
119
  msgid "Post-thumbnails name"
120
  msgstr "Название миниатюры"
121
 
122
- #: related-posts-thumbnails.php:286
123
  msgid "Your theme has to support post-thumbnails to have more choices"
124
- msgstr "Для более широкого выбора размеров, ваша тема должна поддерживать post-thumbnails"
 
 
125
 
126
- #: related-posts-thumbnails.php:291
127
  msgid "Default image URL"
128
  msgstr "Ссылка на картинку по умолчанию, в случае, если нет миниатюры"
129
 
130
- #: related-posts-thumbnails.php:299
131
  msgid "Save Changes"
132
  msgstr "Сохранить изменения"
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
7
  "Project-Id-Version: Related Posts Thubmnails 1.0\n"
8
  "Report-Msgid-Bugs-To: \n"
9
  "POT-Creation-Date: 2010-05-19 17:17-0700\n"
10
+ "PO-Revision-Date: 2010-05-24 17:21-0700\n"
11
  "Last-Translator: M.Shaldybina <mary@shaldybina.com>\n"
12
  "Language-Team: ru_RU <mary@shaldybina.com>\n"
13
  "Language: ru_RU\n"
19
  "X-Poedit-Country: RUSSIA\n"
20
  "X-Poedit-SourceCharset: utf-8\n"
21
 
22
+ #: related-posts-thumbnails.php:148 related-posts-thumbnails.php:194
23
  msgid "Related Posts Thumbnails"
24
  msgstr "Миниатюры похожих записей"
25
 
26
+ #: related-posts-thumbnails.php:148 related-posts-thumbnails.php:194
27
  msgid "Related Posts Thumbs"
28
  msgstr "Похожие записи"
29
 
30
+ #: related-posts-thumbnails.php:154 related-posts-thumbnails.php:200
31
  msgid "No access"
32
  msgstr "Нет доступа"
33
 
34
+ #: related-posts-thumbnails.php:170 related-posts-thumbnails.php:222
35
  msgid "Settings updated"
36
  msgstr "Настройки обновлены"
37
 
38
+ #: related-posts-thumbnails.php:182 related-posts-thumbnails.php:239
39
  msgid "Related Posts Thumbnails Settings"
40
  msgstr "Настройки миниатюр похожих записей"
41
 
42
+ #: related-posts-thumbnails.php:188 related-posts-thumbnails.php:245
43
  msgid "General Display Options"
44
  msgstr "Общие свойства отображения"
45
 
47
  msgid "Display options"
48
  msgstr "Параметр отображения"
49
 
50
+ #: related-posts-thumbnails.php:194 related-posts-thumbnails.php:251
51
  msgid "Show on single posts only"
52
  msgstr "Показывать только на отдельной странице"
53
 
54
+ #: related-posts-thumbnails.php:198 related-posts-thumbnails.php:280
55
  msgid "Top text"
56
  msgstr "Верхний текст"
57
 
58
+ #: related-posts-thumbnails.php:204 related-posts-thumbnails.php:286
59
  msgid "Number of similar posts to display"
60
  msgstr "Количество похожих записей для отображения"
61
 
62
+ #: related-posts-thumbnails.php:212 related-posts-thumbnails.php:360
63
  msgid "Style options"
64
  msgstr "Опции стиля"
65
 
66
+ #: related-posts-thumbnails.php:215 related-posts-thumbnails.php:363
67
  msgid "Background color"
68
  msgstr "Цвет заднего фона"
69
 
70
+ #: related-posts-thumbnails.php:221 related-posts-thumbnails.php:369
71
  msgid "Background color on mouse over"
72
  msgstr "Цвет заднего фона при наведении курсора"
73
 
74
+ #: related-posts-thumbnails.php:227 related-posts-thumbnails.php:375
75
  msgid "Border color"
76
  msgstr "Цвет границы"
77
 
78
+ #: related-posts-thumbnails.php:233 related-posts-thumbnails.php:381
79
  msgid "Font color"
80
  msgstr "Цвет шрифта"
81
 
82
+ #: related-posts-thumbnails.php:239 related-posts-thumbnails.php:387
83
  msgid "Font family"
84
  msgstr "Стиль шрифта"
85
 
86
+ #: related-posts-thumbnails.php:245 related-posts-thumbnails.php:393
87
  msgid "Font size"
88
  msgstr "Размер шрифта"
89
 
90
+ #: related-posts-thumbnails.php:251 related-posts-thumbnails.php:399
91
  msgid "Text maximum length"
92
  msgstr "Максимальная длина текста"
93
 
94
+ #: related-posts-thumbnails.php:259 related-posts-thumbnails.php:407
95
  msgid "Relation Builder Options"
96
  msgstr "Настройки связей"
97
 
98
+ #: related-posts-thumbnails.php:262 related-posts-thumbnails.php:410
99
  msgid "Relation based on"
100
  msgstr "Связи расчитываются на основе"
101
 
102
+ #: related-posts-thumbnails.php:265 related-posts-thumbnails.php:255
103
+ #: related-posts-thumbnails.php:413
104
  msgid "Categories"
105
+ msgstr "Категории"
106
 
107
+ #: related-posts-thumbnails.php:267 related-posts-thumbnails.php:415
108
  msgid "Tags"
109
+ msgstr "Метки"
110
 
111
+ #: related-posts-thumbnails.php:269 related-posts-thumbnails.php:417
112
  msgid "Categories and Tags"
113
+ msgstr "Категории и метки"
114
 
115
  #: related-posts-thumbnails.php:275
116
  msgid "Thumbnails options"
117
  msgstr "Настройки миниатюр"
118
 
119
+ #: related-posts-thumbnails.php:278 related-posts-thumbnails.php:327
120
  msgid "Post-thumbnails name"
121
  msgstr "Название миниатюры"
122
 
123
+ #: related-posts-thumbnails.php:286 related-posts-thumbnails.php:335
124
  msgid "Your theme has to support post-thumbnails to have more choices"
125
+ msgstr ""
126
+ "Для более широкого выбора размеров, ваша тема должна поддерживать post-"
127
+ "thumbnails"
128
 
129
+ #: related-posts-thumbnails.php:291 related-posts-thumbnails.php:292
130
  msgid "Default image URL"
131
  msgstr "Ссылка на картинку по умолчанию, в случае, если нет миниатюры"
132
 
133
+ #: related-posts-thumbnails.php:299 related-posts-thumbnails.php:422
134
  msgid "Save Changes"
135
  msgstr "Сохранить изменения"
136
+
137
+ #: related-posts-thumbnails.php:248
138
+ msgid "Page type"
139
+ msgstr "Тип страницы"
140
+
141
+ #: related-posts-thumbnails.php:270
142
+ msgid "All"
143
+ msgstr "Все"
144
+
145
+ #: related-posts-thumbnails.php:298 related-posts-thumbnails.php:324
146
+ #: related-posts-thumbnails.php:342
147
+ msgid "Thumbnails source"
148
+ msgstr "Источник миниатюр"
149
+
150
+ #: related-posts-thumbnails.php:345
151
+ msgid "Custom field name"
152
+ msgstr "Название произвольного поля"
153
+
154
+ #: related-posts-thumbnails.php:351
155
+ msgid "Size"
156
+ msgstr "Размер"
157
+
158
+ #: related-posts-thumbnails.php:353
159
+ msgid "Width"
160
+ msgstr "Ширина"
161
+
162
+ #: related-posts-thumbnails.php:354
163
+ msgid "Height"
164
+ msgstr "Высота"
165
+
166
+ #: related-posts-thumbnails.php:426
167
+ msgid ""
168
+ "If you experience some problems with this plugin please let me know about it "
169
+ "on <a href=\"http://wordpress.shaldybina.com/plugins/related-posts-"
170
+ "thumbnails/\">Plugin's homepage</a>. If you think this plugin is awesome "
171
+ "please vote on <a href=\"http://wordpress.org/extend/plugins/related-posts-"
172
+ "thumbnails/\">Wordpress plugin page</a>. Thanks!"
173
+ msgstr "Пожалуйста сообщайте об ошибках на <a href=\"http://wordpress.shaldybina.com/plugins/related-posts-thumbnails/\">домашней странице плагина</a>. Если вам понравился плагин, пожалуйста <a href=\"http://wordpress.org/extend/plugins/related-posts-thumbnails/\">проголосуйте</a>. Спасибо!"
readme.txt CHANGED
@@ -4,7 +4,7 @@ Donate link: http://wordpress.shaldybina.com/donate
4
  Tags: related, posts, thumbnail
5
  Requires at least: 2.9
6
  Tested up to: 2.9.2
7
- Stable tag: 0.1
8
 
9
  Customizable plugin, that nicely displays related posts thumbnails under the post.
10
 
@@ -12,11 +12,11 @@ Customizable plugin, that nicely displays related posts thumbnails under the pos
12
 
13
  This plugin will add related posts thumbnails after the post. Plugin allows to customize thumbnail sizes, display settings and type of relation.
14
 
15
- By default it uses generated by Wordpress thumbnail for the first image appeared in the post, that was uploaded on the server with sizes as set in Media settings. You can select between 'thumbnail' and 'medium' size options. In addition if your theme supports Post Thumbnails feature introduced in Wordpress 2.9 you can specify custom thumbnail size.
16
 
17
  Thumbnails are arranged in columns under the post with related posts title under each post thumbnail. Colors of background, border, text, text sizes and background on mouse over can be customized. See screenshot.
18
 
19
- You can specify number of related posts to display, top text, style settings, default image URL. You can select type of relation - categories, tags or categories and tags. You can specify to show related thumbnails on the main page or only on single page.
20
 
21
  Related Links:
22
 
@@ -55,10 +55,19 @@ If there are no images of the specified size in the post, or file does not exist
55
 
56
  == Changelog ==
57
 
58
- = 0.1 =
 
 
 
 
 
 
59
  * Released plugin initial version
60
 
61
  == Upgrade Notice ==
62
 
63
- = 0.1 =
 
 
 
64
  The first released version
4
  Tags: related, posts, thumbnail
5
  Requires at least: 2.9
6
  Tested up to: 2.9.2
7
+ Stable tag: 1.1
8
 
9
  Customizable plugin, that nicely displays related posts thumbnails under the post.
10
 
12
 
13
  This plugin will add related posts thumbnails after the post. Plugin allows to customize thumbnail sizes, display settings and type of relation.
14
 
15
+ By default it uses generated by Wordpress thumbnail for the first image appeared in the post, that was uploaded on the server with sizes as set in Media settings. You can select between 'thumbnail' and 'medium' size options. In addition if your theme supports Post Thumbnails feature introduced in Wordpress 2.9 you can specify custom thumbnail size. You can also specify post custom field name to be used as thumbnails source.
16
 
17
  Thumbnails are arranged in columns under the post with related posts title under each post thumbnail. Colors of background, border, text, text sizes and background on mouse over can be customized. See screenshot.
18
 
19
+ You can specify number of related posts to display, top text, style settings, default image URL. You can select type of relation - categories, tags or categories and tags. You can where to display related posts - specify page type (main or single) and select categories.
20
 
21
  Related Links:
22
 
55
 
56
  == Changelog ==
57
 
58
+ = 1.1 =
59
+ * removed PHP warnings for getimagesize and file if wrong header was received
60
+ * fixed Categories and Tags confusion (when you selected Categories relation was based on Tags and vice versa)
61
+ * added Categories option to select specific categories
62
+ * added post custom field name option as a source for thumbnails
63
+
64
+ = 1.0 =
65
  * Released plugin initial version
66
 
67
  == Upgrade Notice ==
68
 
69
+ = 1.1 =
70
+ This version includes categories/tags confusion in settings, elimination of warnings in case of wrong headers, new features - Categories and custom field support.
71
+
72
+ = 1.0 =
73
  The first released version
related-posts-thumbnails.php CHANGED
@@ -2,7 +2,7 @@
2
  Plugin Name: Related Posts Thumbnails
3
  Plugin URI: http://wordpress.shaldybina.com/plugins/related-posts-thumbnails/
4
  Description: Showing related posts thumbnails under the post.
5
- Version: 1.0
6
  Author: Maria Shaldybina
7
  Author URI: http://shaldybina.com/
8
  */
@@ -34,6 +34,11 @@ class RelatedPostsThumbnails {
34
  public $font_family = 'Arial';
35
  public $font_size = '12';
36
  public $text_length = '100';
 
 
 
 
 
37
 
38
  function RelatedPostsThumbnails() { // initialization
39
  load_plugin_textdomain( 'related-posts-thumbnails', false, basename( dirname( __FILE__ ) ) . '/locale' );
@@ -42,7 +47,7 @@ class RelatedPostsThumbnails {
42
  add_action( 'admin_menu', array( $this, 'admin_menu' ) );
43
  }
44
 
45
- function relpoststh_show($content) { // Displaying related posts on the site
46
  if ( $this->is_relpoststh_show() ) {
47
  $content .= get_option( 'relpoststh_top_text', $this->top_text );
48
  $content .= $this->relpoststh_get();
@@ -51,38 +56,37 @@ class RelatedPostsThumbnails {
51
  }
52
 
53
  function relpoststh_get() { // Retrieve Related Posts HTML for output
54
- $id = get_the_ID();
55
- $relation = get_option( 'relpoststh_relation', $this->relation );
56
- $posts_number = get_option( 'relpoststh_number', $this->number );
57
- $poststhname = get_option( 'relpoststh_poststhname', $this->poststhname );
58
- $text_length = get_option( 'relpoststh_textlength', $this->text_length );
59
-
60
- $args = array( 'orderby' => 'rand',
61
- 'caller_get_posts' => true,
62
- 'posts_per_page' => $posts_number,
63
- 'post__not_in' => array( $id ) );
64
-
65
- $posts = array();
66
- $q = new WP_Query;
67
-
68
- if ( $poststhname == 'thumbnail' || $poststhname == 'medium' || $poststhname == 'large' ) { // get thumbnail size for basic sizes
69
- $width = get_option( "{$poststhname}_size_w" );
70
- $height = get_option( "{$poststhname}_size_h" );
71
- }
72
- elseif ( current_theme_supports( 'post-thumbnails' ) ) { // get sizes for theme supported thumbnails
73
- global $_wp_additional_image_sizes;
74
- $width = $_wp_additional_image_sizes[ $poststhname ][ 'width' ];
75
- $height = $_wp_additional_image_sizes[ $poststhname ][ 'height' ];
76
- }
77
 
78
  /* Getting posts by relation */
79
  if ( $relation == 'categories' || $relation == 'both' ) {
80
- $query_args = array( 'tag__in' => wp_get_object_terms( $id, array( 'post_tag' ), array( 'fields' => 'ids' ) ) );
 
 
 
 
 
 
 
 
 
81
  $posts = array_merge( $posts, $q->query( array_merge( $args, $query_args ) ) );
82
  }
83
 
84
  if ( $relation == 'tags' || $relation == 'both' ) {
85
- $query_args = array( 'category__in' => wp_get_object_terms( $id, array( 'category' ), array( 'fields' => 'ids' ) ) );
86
  $posts = array_merge( $posts, $q->query( array_merge( $args, $query_args ) ) );
87
  }
88
 
@@ -94,33 +98,59 @@ class RelatedPostsThumbnails {
94
  $posts = array_slice( $posts_unique, 0, $posts_number );
95
  }
96
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
97
  if ( count( $posts ) ) { // rendering related posts HTML
98
  $output = '<div style="clear: both"></div><div style="border: 0pt none ; margin: 0pt; padding: 0pt;">';
99
  foreach( $posts as $post ) {
100
  $image = '';
101
  $url = '';
102
- if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) { // using built in Wordpress feature
103
- $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
104
- if ( $post_thumbnail_id ) {
105
- $image = wp_get_attachment_image_src( $post_thumbnail_id, $poststhname );
106
- $url = $image[0];
107
- }
108
  }
109
- else { // Theme does not support post-thumbnails, or post does not have assigned thumbnail
110
- $wud = wp_upload_dir();
111
- preg_match_all( '|<img.*?src=[\'"](' . $wud['baseurl'] . '.*?)[\'"].*?>|i', $post->post_content, $matches ); // searching for the first uploaded image in text
112
- if ( isset( $matches ) ) $image = $matches[1][0];
113
- if ( strlen( trim( $image ) ) > 0 ) {
114
- $image_sizes = getimagesize( $image );
115
- if ( $image_sizes[0] == $width ) { // if this image is the same size as we need
116
- $url = $image;
117
  }
118
- else { // if not, search for resized thumbnail according to Wordpress thumbnails naming function
119
- $url = preg_replace( '/(-[0-9]+x[0-9]+)?(\.[^\.]*)$/', '-' . $width . 'x' . $height . '$2', $image );
 
 
 
 
 
 
 
 
 
 
 
120
  }
121
  }
122
  }
123
- if ( empty( $url ) || false === file( $url ) ) { // using default image if no image was found or no such file on server
124
  $url = get_option( 'relpoststh_default_image', $this->default_image );
125
  }
126
  $title = ( strlen( $post->post_title ) > $text_length ) ? substr( $post->post_title, 0, $text_length) . '...' : $post->post_title;
@@ -138,7 +168,23 @@ class RelatedPostsThumbnails {
138
  }
139
 
140
  function is_relpoststh_show() { // Checking display options
141
- return ( is_single() || ! get_option( 'relpoststh_single_only', $this->single_only ) );
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
142
  }
143
 
144
  /**
@@ -167,6 +213,12 @@ class RelatedPostsThumbnails {
167
  update_option( 'relpoststh_fontsize', $_POST['relpoststh_fontsize'] );
168
  update_option( 'relpoststh_fontfamily', $_POST['relpoststh_fontfamily'] );
169
  update_option( 'relpoststh_textlength', $_POST['relpoststh_textlength'] );
 
 
 
 
 
 
170
  echo "<div class='updated fade'><p>" . __( 'Settings updated', 'related-posts-thumbnails' ) ."</p></div>";
171
  }
172
  $available_sizes = array( 'thumbnail' => 'thumbnail', 'medium' => 'medium' );
@@ -176,6 +228,11 @@ class RelatedPostsThumbnails {
176
  }
177
  $relpoststh_single_only = get_option( 'relpoststh_single_only', $this->single_only );
178
  $relpoststh_relation = get_option( 'relpoststh_relation', $this->relation );
 
 
 
 
 
179
  ?>
180
  <div class="wrap">
181
  <div class="icon32" id="icon-options-general"><br></div>
@@ -188,12 +245,37 @@ class RelatedPostsThumbnails {
188
  <h3><?php _e( 'General Display Options', 'related-posts-thumbnails' ); ?>:</h3>
189
  <table class="form-table">
190
  <tr valign="top">
191
- <th scope="row"><?php _e( 'Display options', 'related-posts-thumbnails' ); ?>:</th>
192
  <td>
193
  <input type="checkbox" name="relpoststh_single_only" id="relpoststh_single_only" value="1" <?php if ( $relpoststh_single_only ) echo 'checked="checked"'; ?>/>
194
  <label for="relpoststh_single_only"><?php _e( 'Show on single posts only', 'related-posts-thumbnails' ); ?></label><br />
195
  </td>
196
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
197
  <tr>
198
  <th scope="row"><?php _e( 'Top text', 'related-posts-thumbnails' ); ?>:</th>
199
  <td>
@@ -206,6 +288,72 @@ class RelatedPostsThumbnails {
206
  <input type="text" name="relpoststh_number" value="<?php echo get_option( 'relpoststh_number', $this->number ); ?>" size="2"/>
207
  </td>
208
  </tr>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
209
  </table>
210
  </div>
211
  <div class="postbox">
@@ -271,35 +419,11 @@ class RelatedPostsThumbnails {
271
  </tr>
272
  </table>
273
  </div>
274
- <div class="postbox">
275
- <h3><?php _e( 'Thumbnails options', 'related-posts-thumbnails' ); ?>:</h3>
276
- <table class="form-table">
277
- <tr valign="top">
278
- <th scope="row"><?php _e( 'Post-thumbnails name', 'related-posts-thumbnails' ); ?>:</th>
279
- <td>
280
- <select name="relpoststh_poststhname">
281
- <?php foreach ( $available_sizes as $size_name => $size ) : ?>
282
- <option <?php if ( $size_name == get_option('relpoststh_poststhname', $this->poststhname) ) echo 'selected'; ?>><?php echo $size_name; ?></option>
283
- <?php endforeach; ?>
284
- </select>
285
- <?php if ( !current_theme_supports( 'post-thumbnails' ) ) : ?>
286
- (<?php _e( 'Your theme has to support post-thumbnails to have more choices', 'related-posts-thumbnails' ); ?>)
287
- <?php endif; ?>
288
- </td>
289
- </tr>
290
- <tr>
291
- <th scope="row"><?php _e( 'Default image URL', 'related-posts-thumbnails' ); ?>:</th>
292
- <td>
293
- <input type="text" name="relpoststh_default_image" value="<?php echo get_option('relpoststh_default_image', $this->default_image );?>" size="50"/>
294
- </td>
295
- </tr>
296
- </table>
297
- </div>
298
-
299
  <input name="Submit" value="<?php _e( 'Save Changes', 'related-posts-thumbnails' ); ?>" type="submit">
300
  </div>
301
  </form>
302
  </div>
 
303
  <?php
304
  }
305
  }
2
  Plugin Name: Related Posts Thumbnails
3
  Plugin URI: http://wordpress.shaldybina.com/plugins/related-posts-thumbnails/
4
  Description: Showing related posts thumbnails under the post.
5
+ Version: 1.1
6
  Author: Maria Shaldybina
7
  Author URI: http://shaldybina.com/
8
  */
34
  public $font_family = 'Arial';
35
  public $font_size = '12';
36
  public $text_length = '100';
37
+ public $custom_field = '';
38
+ public $custom_height = '100';
39
+ public $custom_width = '100';
40
+ public $thsource = 'post-thumbnails';
41
+ public $categories_all = '1';
42
 
43
  function RelatedPostsThumbnails() { // initialization
44
  load_plugin_textdomain( 'related-posts-thumbnails', false, basename( dirname( __FILE__ ) ) . '/locale' );
47
  add_action( 'admin_menu', array( $this, 'admin_menu' ) );
48
  }
49
 
50
+ function relpoststh_show( $content ) { // Displaying related posts on the site
51
  if ( $this->is_relpoststh_show() ) {
52
  $content .= get_option( 'relpoststh_top_text', $this->top_text );
53
  $content .= $this->relpoststh_get();
56
  }
57
 
58
  function relpoststh_get() { // Retrieve Related Posts HTML for output
59
+ $id = get_the_ID();
60
+ $relation = get_option( 'relpoststh_relation', $this->relation );
61
+ $posts_number = get_option( 'relpoststh_number', $this->number );
62
+ $poststhname = get_option( 'relpoststh_poststhname', $this->poststhname );
63
+ $text_length = get_option( 'relpoststh_textlength', $this->text_length );
64
+ $thsource = get_option( 'relpoststh_thsource', $this->thsource );
65
+ $categories_all = get_option( 'relpoststh_categoriesall', $this->categories_all );
66
+ $posts = array();
67
+ $q = new WP_Query;
68
+ $args = array( 'orderby' => 'rand',
69
+ 'caller_get_posts' => true,
70
+ 'posts_per_page' => $posts_number,
71
+ 'post__not_in' => array( $id ) );
 
 
 
 
 
 
 
 
 
 
72
 
73
  /* Getting posts by relation */
74
  if ( $relation == 'categories' || $relation == 'both' ) {
75
+ $query_args = array( 'category__in' => wp_get_object_terms( $id, array( 'category' ), array( 'fields' => 'ids' ) ) );
76
+ if ( $categories_all != '1') { // if only specific categories were selected
77
+ $relpoststh_categories = unserialize( get_option( 'relpoststh_categories' ) );
78
+ if ( !is_array( $relpoststh_categories ) )
79
+ $relpoststh_categories = array();
80
+ $query_args['category__in'] = array_intersect( $relpoststh_categories, $query_args['category__in'] );
81
+ if ( empty( $query_args['category__in'] ) ) {
82
+ $query_args['category__in'] = array(0); // if no categories were specified return nothing
83
+ }
84
+ }
85
  $posts = array_merge( $posts, $q->query( array_merge( $args, $query_args ) ) );
86
  }
87
 
88
  if ( $relation == 'tags' || $relation == 'both' ) {
89
+ $query_args = array( 'tag__in' => wp_get_object_terms( $id, array( 'post_tag' ), array( 'fields' => 'ids' ) ) );
90
  $posts = array_merge( $posts, $q->query( array_merge( $args, $query_args ) ) );
91
  }
92
 
98
  $posts = array_slice( $posts_unique, 0, $posts_number );
99
  }
100
 
101
+ if ( $thsource == 'custom-field' ) {
102
+ $width = get_option( 'relpoststh_customwidth', $this->custom_width );
103
+ $height = get_option( 'relpoststh_customheight', $this->custom_height );
104
+ }
105
+ else { // post-thumbnails source
106
+ if ( $poststhname == 'thumbnail' || $poststhname == 'medium' || $poststhname == 'large' ) { // get thumbnail size for basic sizes
107
+ $width = get_option( "{$poststhname}_size_w" );
108
+ $height = get_option( "{$poststhname}_size_h" );
109
+ }
110
+ elseif ( current_theme_supports( 'post-thumbnails' ) ) { // get sizes for theme supported thumbnails
111
+ global $_wp_additional_image_sizes;
112
+ $width = $_wp_additional_image_sizes[ $poststhname ][ 'width' ];
113
+ $height = $_wp_additional_image_sizes[ $poststhname ][ 'height' ];
114
+ }
115
+ else { // theme is not supporting but settings were not changed
116
+ $poststhname = 'thumbnail';
117
+ $width = get_option( "thumbnail_size_w" );
118
+ $height = get_option( "thumbnail_size_h" );
119
+ }
120
+ }
121
+
122
  if ( count( $posts ) ) { // rendering related posts HTML
123
  $output = '<div style="clear: both"></div><div style="border: 0pt none ; margin: 0pt; padding: 0pt;">';
124
  foreach( $posts as $post ) {
125
  $image = '';
126
  $url = '';
127
+ if ( $thsource == 'custom-field' ) {
128
+ $url = get_post_meta( $post->ID, get_option( 'relpoststh_customfield', $this->custom_field ), true );
 
 
 
 
129
  }
130
+ else {
131
+ if ( current_theme_supports( 'post-thumbnails' ) && has_post_thumbnail( $post->ID ) ) { // using built in Wordpress feature
132
+ $post_thumbnail_id = get_post_thumbnail_id( $post->ID );
133
+ if ( $post_thumbnail_id ) {
134
+ $image = wp_get_attachment_image_src( $post_thumbnail_id, $poststhname );
135
+ $url = $image[0];
 
 
136
  }
137
+ }
138
+ else { // Theme does not support post-thumbnails, or post does not have assigned thumbnail
139
+ $wud = wp_upload_dir();
140
+ preg_match_all( '|<img.*?src=[\'"](' . $wud['baseurl'] . '.*?)[\'"].*?>|i', $post->post_content, $matches ); // searching for the first uploaded image in text
141
+ if ( isset( $matches ) ) $image = $matches[1][0];
142
+ if ( strlen( trim( $image ) ) > 0 ) {
143
+ $image_sizes = @getimagesize( $image );
144
+ if ( isset( $image_sizes[0] ) && $image_sizes[0] == $width ) { // if this image is the same size as we need
145
+ $url = $image;
146
+ }
147
+ else { // if not, search for resized thumbnail according to Wordpress thumbnails naming function
148
+ $url = preg_replace( '/(-[0-9]+x[0-9]+)?(\.[^\.]*)$/', '-' . $width . 'x' . $height . '$2', $image );
149
+ }
150
  }
151
  }
152
  }
153
+ if ( empty( $url ) || false === @fopen( $url, 'r' ) ) { // using default image if no image was found or no such file on server
154
  $url = get_option( 'relpoststh_default_image', $this->default_image );
155
  }
156
  $title = ( strlen( $post->post_title ) > $text_length ) ? substr( $post->post_title, 0, $text_length) . '...' : $post->post_title;
168
  }
169
 
170
  function is_relpoststh_show() { // Checking display options
171
+ if ( ! is_single() && get_option( 'relpoststh_single_only', $this->single_only ) ) { // single only
172
+ return false;
173
+ }
174
+ /* Check categories */
175
+ $id = get_the_ID();
176
+ $categories_all = get_option( 'relpoststh_categoriesall', $this->categories_all );
177
+ if ( $categories_all != '1') { // only specific categories were selected
178
+ $post_categories = wp_get_object_terms( $id, array( 'category' ), array( 'fields' => 'ids' ) );
179
+ $relpoststh_categories = unserialize( get_option( 'relpoststh_categories' ) );
180
+ if ( !is_array( $relpoststh_categories ) )
181
+ $relpoststh_categories = array();
182
+ $common_categories = array_intersect( $relpoststh_categories, $post_categories );
183
+ if ( empty( $common_categories ) ) { // post doesn't belong to specified categories
184
+ return false;
185
+ }
186
+ }
187
+ return true;
188
  }
189
 
190
  /**
213
  update_option( 'relpoststh_fontsize', $_POST['relpoststh_fontsize'] );
214
  update_option( 'relpoststh_fontfamily', $_POST['relpoststh_fontfamily'] );
215
  update_option( 'relpoststh_textlength', $_POST['relpoststh_textlength'] );
216
+ update_option( 'relpoststh_thsource', $_POST['relpoststh_thsource'] );
217
+ update_option( 'relpoststh_customfield', $_POST['relpoststh_customfield'] );
218
+ update_option( 'relpoststh_customwidth', $_POST['relpoststh_customwidth'] );
219
+ update_option( 'relpoststh_customheight', $_POST['relpoststh_customheight'] );
220
+ update_option( 'relpoststh_categoriesall', $_POST['relpoststh_categoriesall'] );
221
+ update_option( 'relpoststh_categories', serialize( $_POST['relpoststh_categories'] ) );
222
  echo "<div class='updated fade'><p>" . __( 'Settings updated', 'related-posts-thumbnails' ) ."</p></div>";
223
  }
224
  $available_sizes = array( 'thumbnail' => 'thumbnail', 'medium' => 'medium' );
228
  }
229
  $relpoststh_single_only = get_option( 'relpoststh_single_only', $this->single_only );
230
  $relpoststh_relation = get_option( 'relpoststh_relation', $this->relation );
231
+ $relpoststh_thsource = get_option( 'relpoststh_thsource', $this->thsource );
232
+ $relpoststh_categoriesall = get_option( 'relpoststh_categoriesall', $this->categories_all );
233
+ $relpoststh_categories = unserialize( get_option( 'relpoststh_categories' ) );
234
+ $thsources = array( 'post-thumbnails' => 'Post thumbnails', 'custom-field' => 'Custom field' );
235
+ $categories = get_categories();
236
  ?>
237
  <div class="wrap">
238
  <div class="icon32" id="icon-options-general"><br></div>
245
  <h3><?php _e( 'General Display Options', 'related-posts-thumbnails' ); ?>:</h3>
246
  <table class="form-table">
247
  <tr valign="top">
248
+ <th scope="row"><?php _e( 'Page type', 'related-posts-thumbnails' ); ?>:</th>
249
  <td>
250
  <input type="checkbox" name="relpoststh_single_only" id="relpoststh_single_only" value="1" <?php if ( $relpoststh_single_only ) echo 'checked="checked"'; ?>/>
251
  <label for="relpoststh_single_only"><?php _e( 'Show on single posts only', 'related-posts-thumbnails' ); ?></label><br />
252
  </td>
253
  </tr>
254
+ <tr valign="top">
255
+ <th scope="row"><?php _e( 'Categories', 'related-posts-thumbnails' ); ?>:</th>
256
+ <td>
257
+ <script type="text/javascript">
258
+ jQuery(document).ready(function($) {
259
+ $('#categories_all').click(function(){
260
+ if (this.checked) {
261
+ $('#categories_specific').hide();
262
+ }
263
+ else {
264
+ $('#categories_specific').show();
265
+ }
266
+ });
267
+ });
268
+ </script>
269
+ <input type="checkbox" id="categories_all" name="relpoststh_categoriesall" value="1" <?php if ( $relpoststh_categoriesall == '1' ) echo 'checked="checked"'; ?>/>
270
+ <label for="categories_all"><?php _e( 'All', 'related-posts-thumbnails' ); ?></label>
271
+ <div id="categories_specific" <?php if ( $relpoststh_categoriesall == '1' ) : ?> style="display:none" <?php endif; ?>>
272
+ <?php foreach ( $categories as $category ) : ?>
273
+ <input type="checkbox" name="relpoststh_categories[]" id="relpoststh_<?php echo $category->category_nicename; ?>" value="<?php echo $category->cat_ID; ?>" <?php if ( in_array( $category->cat_ID, (array)$relpoststh_categories ) ) echo 'checked="checked"'; ?>/>
274
+ <label for="relpoststh_<?php echo $category->category_nicename; ?>"><?php echo $category->cat_name; ?></label><br />
275
+ <?php endforeach; ?>
276
+ </div>
277
+ </td>
278
+ </tr>
279
  <tr>
280
  <th scope="row"><?php _e( 'Top text', 'related-posts-thumbnails' ); ?>:</th>
281
  <td>
288
  <input type="text" name="relpoststh_number" value="<?php echo get_option( 'relpoststh_number', $this->number ); ?>" size="2"/>
289
  </td>
290
  </tr>
291
+ <tr>
292
+ <th scope="row"><?php _e( 'Default image URL', 'related-posts-thumbnails' ); ?>:</th>
293
+ <td>
294
+ <input type="text" name="relpoststh_default_image" value="<?php echo get_option('relpoststh_default_image', $this->default_image );?>" size="50"/>
295
+ </td>
296
+ </tr>
297
+ <tr>
298
+ <th scope="row"><?php _e( 'Thumbnails source', 'related-posts-thumbnails' ); ?>:</th>
299
+ <td>
300
+ <script type="text/javascript">
301
+ jQuery(document).ready(function($) {
302
+ $('#relpoststh_thsource').change(function(){
303
+ if (this.value == 'post-thumbnails') {
304
+ $('#relpoststh-post-thumbnails').show();
305
+ $('#relpoststh-custom-field').hide();
306
+ }
307
+ else {
308
+ $('#relpoststh-post-thumbnails').hide();
309
+ $('#relpoststh-custom-field').show();
310
+ }
311
+ });
312
+ });
313
+ </script>
314
+ <select name="relpoststh_thsource" id="relpoststh_thsource">
315
+ <?php foreach ( $thsources as $name => $title ) : ?>
316
+ <option value="<?php echo $name; ?>" <?php if ( $relpoststh_thsource == $name ) echo 'selected'; ?>><?php echo $title; ?></option>
317
+ <?php endforeach; ?>
318
+ </select>
319
+ </td>
320
+ </tr>
321
+ </table>
322
+ </div>
323
+ <div class="postbox" id="relpoststh-post-thumbnails" <?php if ( $relpoststh_thsource != 'post-thumbnails' ) : ?> style="display:none" <?php endif; ?>>
324
+ <h3><?php _e( 'Thumbnails source', 'related-posts-thumbnails' ); ?>:</h3>
325
+ <table class="form-table">
326
+ <tr valign="top">
327
+ <th scope="row"><?php _e( 'Post-thumbnails name', 'related-posts-thumbnails' ); ?>:</th>
328
+ <td>
329
+ <select name="relpoststh_poststhname">
330
+ <?php foreach ( $available_sizes as $size_name => $size ) : ?>
331
+ <option <?php if ( $size_name == get_option('relpoststh_poststhname', $this->poststhname) ) echo 'selected'; ?>><?php echo $size_name; ?></option>
332
+ <?php endforeach; ?>
333
+ </select>
334
+ <?php if ( !current_theme_supports( 'post-thumbnails' ) ) : ?>
335
+ (<?php _e( 'Your theme has to support post-thumbnails to have more choices', 'related-posts-thumbnails' ); ?>)
336
+ <?php endif; ?>
337
+ </td>
338
+ </tr>
339
+ </table>
340
+ </div>
341
+ <div class="postbox" id="relpoststh-custom-field" <?php if ( $relpoststh_thsource != 'custom-field' ) : ?> style="display:none" <?php endif; ?>>
342
+ <h3><?php _e( 'Thumbnails source', 'related-posts-thumbnails' ); ?>:</h3>
343
+ <table class="form-table">
344
+ <tr valign="top">
345
+ <th scope="row"><?php _e( 'Custom field name', 'related-posts-thumbnails' ); ?>:</th>
346
+ <td>
347
+ <input type="text" name="relpoststh_customfield" value="<?php echo get_option('relpoststh_customfield', $this->custom_field );?>" size="50"/>
348
+ </td>
349
+ </tr>
350
+ <tr valign="top">
351
+ <th scope="row"><?php _e( 'Size', 'related-posts-thumbnails' ); ?>:</th>
352
+ <td>
353
+ <?php _e( 'Width', 'related-posts-thumbnails' ); ?>: <input type="text" name="relpoststh_customwidth" value="<?php echo get_option('relpoststh_customwidth', $this->custom_width );?>" size="3"/>px x
354
+ <?php _e( 'Height', 'related-posts-thumbnails' ); ?>: <input type="text" name="relpoststh_customheight" value="<?php echo get_option('relpoststh_customheight', $this->custom_height );?>" size="3"/>px
355
+ </td>
356
+ </tr>
357
  </table>
358
  </div>
359
  <div class="postbox">
419
  </tr>
420
  </table>
421
  </div>
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
422
  <input name="Submit" value="<?php _e( 'Save Changes', 'related-posts-thumbnails' ); ?>" type="submit">
423
  </div>
424
  </form>
425
  </div>
426
+ <p style="margin-top: 40px;"><small><?php _e('If you experience some problems with this plugin please let me know about it on <a href="http://wordpress.shaldybina.com/plugins/related-posts-thumbnails/">Plugin\'s homepage</a>. If you think this plugin is awesome please vote on <a href="http://wordpress.org/extend/plugins/related-posts-thumbnails/">Wordpress plugin page</a>. Thanks!', 'related-posts-thumbnails' ); ?></small></p>
427
  <?php
428
  }
429
  }
screenshot-2.png CHANGED
Binary file