Contextual Related Posts - Version 3.0.3

Version Description

Release post: https://webberzone.com/blog/contextual-related-posts-v3-0-0/

  • Enhancement/Modifications:

    • Grid style minimum width is now decided by the width of the thumbnail and long words are wrapped
  • Bug fixes:

    • Selecting No style created a 404 error
    • Fixed issue with $attachment_id not being declared in some cases
Download this release

Release Info

Developer Ajay
Plugin Icon 128x128 Contextual Related Posts
Version 3.0.3
Comparing to
See all releases

Code changes from version 3.0.2 to 3.0.3

contextual-related-posts.php CHANGED
@@ -15,7 +15,7 @@
15
  * Plugin Name: Contextual Related Posts
16
  * Plugin URI: https://webberzone.com/plugins/contextual-related-posts/
17
  * Description: Display a set of related posts on your website or in your feed. Increase reader retention and reduce bounce rates
18
- * Version: 3.0.2
19
  * Author: WebberZone
20
  * Author URI: https://webberzone.com
21
  * License: GPL-2.0+
15
  * Plugin Name: Contextual Related Posts
16
  * Plugin URI: https://webberzone.com/plugins/contextual-related-posts/
17
  * Description: Display a set of related posts on your website or in your feed. Increase reader retention and reduce bounce rates
18
+ * Version: 3.0.3
19
  * Author: WebberZone
20
  * Author URI: https://webberzone.com
21
  * License: GPL-2.0+
css/grid.css CHANGED
@@ -7,7 +7,6 @@
7
  }
8
  .crp_related ul {
9
  display: grid;
10
- grid-template-columns: repeat(auto-fill, minmax(150px, 1fr));
11
  gap: 10px;
12
  margin: 0;
13
  justify-items: center;
@@ -15,6 +14,7 @@
15
  }
16
  .crp_related ul li {
17
  text-align:left;
 
18
  }
19
  .crp_related .crp_thumb, .crp_related .crp_title {
20
  display: block;
7
  }
8
  .crp_related ul {
9
  display: grid;
 
10
  gap: 10px;
11
  margin: 0;
12
  justify-items: center;
14
  }
15
  .crp_related ul li {
16
  text-align:left;
17
+ word-break: break-word;
18
  }
19
  .crp_related .crp_thumb, .crp_related .crp_title {
20
  display: block;
css/grid.min.css CHANGED
@@ -1 +1 @@
1
- .crp_related{clear:both;margin:10px 0}.crp_related h3{margin:0!important}.crp_related ul{display:grid;grid-template-columns:repeat(auto-fill,minmax(150px,1fr));gap:10px;margin:0;justify-items:center;list-style:none}.crp_related ul li{text-align:left}.crp_related .crp_thumb,.crp_related .crp_title{display:block;margin:0 auto}.crp_related ul li a{text-decoration:none!important}.crp_related ul li img{max-width:100%;height:auto;display:block;margin:0 auto}.crp_clear{clear:both}.crp_author,.crp_date,.crp_excerpt{display:block;font-size:.9em}
1
+ .crp_related{clear:both;margin:10px 0}.crp_related h3{margin:0!important}.crp_related ul{display:grid;gap:10px;margin:0;justify-items:center;list-style:none}.crp_related ul li{text-align:left;word-break:break-word}.crp_related .crp_thumb,.crp_related .crp_title{display:block;margin:0 auto}.crp_related ul li a{text-decoration:none!important}.crp_related ul li img{max-width:100%;height:auto;display:block;margin:0 auto}.crp_clear{clear:both}.crp_author,.crp_date,.crp_excerpt{display:block;font-size:.9em}
css/thumbs-grid.css CHANGED
@@ -14,6 +14,7 @@
14
  border: 1px solid #ddd;
15
  display: flex;
16
  flex-direction: column;
 
17
  }
18
  .crp_related li:hover {
19
  background: #eee;
14
  border: 1px solid #ddd;
15
  display: flex;
16
  flex-direction: column;
17
+ word-break: break-word;
18
  }
19
  .crp_related li:hover {
20
  background: #eee;
css/thumbs-grid.min.css CHANGED
@@ -1 +1 @@
1
- .crp_related{clear:both;margin:10px 0}.crp_related ul{display:grid;grid-gap:10px;margin:0;justify-items:center;list-style:none}.crp_related ul li{text-align:center;border:1px solid #ddd;display:flex;flex-direction:column}.crp_related li:hover{background:#eee;border-color:#bbb}.crp_related ul li a.crp_link{flex-grow:1;display:grid;overflow:hidden;padding:3px}.crp_related ul li a.crp_link .crp_thumb{grid-row-start:1;grid-row-end:3;grid-column-start:1;grid-column-end:2}.crp_related ul li a.crp_link .crp_title{display:flex;justify-content:center;align-items:center;grid-row-start:2;grid-row-end:3;grid-column-start:1;grid-column-end:2}.crp_related a{-webkit-box-shadow:none!important;-moz-box-shadow:none!important;box-shadow:none!important;text-decoration:none!important}.crp_related a:hover{text-decoration:none}.crp_related ul li img{max-width:100%;height:auto;display:block;margin:0 auto}.crp_related .crp_title{color:#fff!important;padding:3px;font-size:.9em;text-shadow:.1em .1em .2em #000;background-color:rgba(0,0,0,.5);-webkit-border-radius:7px;-moz-border-radius:7px;border-radius:7px;width:100%;overflow:hidden;line-height:initial}.crp_related li:hover .crp_title{background-color:rgba(0,0,0,.8)}.crp_related li{vertical-align:bottom;-webkit-box-shadow:0 1px 2px rgba(0,0,0,.4);-moz-box-shadow:0 1px 2px rgba(0,0,0,.4);box-shadow:0 1px 2px rgba(0,0,0,.4);-webkit-border-radius:7px;-moz-border-radius:7px;border-radius:7px;list-style-type:none}.crp_clear{clear:both}.crp_title:visited{color:#fff!important}
1
+ .crp_related{clear:both;margin:10px 0}.crp_related ul{display:grid;grid-gap:10px;margin:0;justify-items:center;list-style:none}.crp_related ul li{text-align:center;border:1px solid #ddd;display:flex;flex-direction:column;word-break:break-word}.crp_related li:hover{background:#eee;border-color:#bbb}.crp_related ul li a.crp_link{flex-grow:1;display:grid;overflow:hidden;padding:3px}.crp_related ul li a.crp_link .crp_thumb{grid-row-start:1;grid-row-end:3;grid-column-start:1;grid-column-end:2}.crp_related ul li a.crp_link .crp_title{display:flex;justify-content:center;align-items:center;grid-row-start:2;grid-row-end:3;grid-column-start:1;grid-column-end:2}.crp_related a{-webkit-box-shadow:none!important;-moz-box-shadow:none!important;box-shadow:none!important;text-decoration:none!important}.crp_related a:hover{text-decoration:none}.crp_related ul li img{max-width:100%;height:auto;display:block;margin:0 auto}.crp_related .crp_title{color:#fff!important;padding:3px;font-size:.9em;text-shadow:.1em .1em .2em #000;background-color:rgba(0,0,0,.5);-webkit-border-radius:7px;-moz-border-radius:7px;border-radius:7px;width:100%;overflow:hidden;line-height:initial}.crp_related li:hover .crp_title{background-color:rgba(0,0,0,.8)}.crp_related li{vertical-align:bottom;-webkit-box-shadow:0 1px 2px rgba(0,0,0,.4);-moz-box-shadow:0 1px 2px rgba(0,0,0,.4);box-shadow:0 1px 2px rgba(0,0,0,.4);-webkit-border-radius:7px;-moz-border-radius:7px;border-radius:7px;list-style-type:none}.crp_clear{clear:both}.crp_title:visited{color:#fff!important}
includes/header.php CHANGED
@@ -51,7 +51,7 @@ function crp_heading_styles() {
51
 
52
  $style_array = crp_get_style();
53
 
54
- if ( ! empty( $style_array ) ) {
55
  $style = $style_array['name'];
56
  $extra_css = $style_array['extra_css'];
57
 
@@ -66,6 +66,8 @@ add_action( 'wp_enqueue_scripts', 'crp_heading_styles' );
66
  /**
67
  * Get the current style for the related posts.
68
  *
 
 
69
  * @return array Contains two elements:
70
  * 'name' holding style name and 'extra_css' to be added inline.
71
  */
@@ -102,7 +104,11 @@ function crp_get_style() {
102
 
103
  case 'grid':
104
  $style['name'] = 'grid';
105
- $style['extra_css'] = '';
 
 
 
 
106
  break;
107
 
108
  case 'thumbs_grid':
51
 
52
  $style_array = crp_get_style();
53
 
54
+ if ( ! empty( $style_array['name'] ) ) {
55
  $style = $style_array['name'];
56
  $extra_css = $style_array['extra_css'];
57
 
66
  /**
67
  * Get the current style for the related posts.
68
  *
69
+ * @since 3.0.0
70
+ *
71
  * @return array Contains two elements:
72
  * 'name' holding style name and 'extra_css' to be added inline.
73
  */
104
 
105
  case 'grid':
106
  $style['name'] = 'grid';
107
+ $style['extra_css'] = "
108
+ .crp_related ul {
109
+ grid-template-columns: repeat(auto-fill, minmax({$thumb_width}px, 1fr));
110
+ }
111
+ ";
112
  break;
113
 
114
  case 'thumbs_grid':
includes/media.php CHANGED
@@ -90,9 +90,9 @@ function crp_get_the_post_thumbnail( $args = array() ) {
90
  $postimage = get_post_meta( $result->ID, $args['thumb_meta'], true );
91
  $pick = 'meta';
92
  if ( $postimage ) {
93
- $postimage_id = crp_get_attachment_id_from_url( $postimage );
94
 
95
- $postthumb = wp_get_attachment_image_src( $postimage_id, array( $args['thumb_width'], $args['thumb_height'] ) );
96
  if ( false !== $postthumb ) {
97
  $postimage = $postthumb[0];
98
  $pick .= 'correct';
@@ -135,9 +135,9 @@ function crp_get_the_post_thumbnail( $args = array() ) {
135
  }
136
  $pick = 'first';
137
  if ( $postimage ) {
138
- $postimage_id = crp_get_attachment_id_from_url( $postimage );
139
 
140
- $postthumb = wp_get_attachment_image_src( $postimage_id, array( $args['thumb_width'], $args['thumb_height'] ) );
141
  if ( false !== $postthumb ) {
142
  $postimage = $postthumb[0];
143
  $pick .= 'correct';
@@ -181,25 +181,6 @@ function crp_get_the_post_thumbnail( $args = array() ) {
181
  */
182
  $postimage = apply_filters( 'crp_thumb_url', $postimage, $args['thumb_width'], $args['thumb_height'], $result );
183
 
184
- /* Backward compatibility */
185
- $thumb_timthumb = false;
186
- $thumb_timthumb_q = 75;
187
-
188
- /**
189
- * Filters the thumbnail image URL.
190
- *
191
- * @since 1.8.10
192
- * @deprecated 2.1 Use crp_thumb_url instead.
193
- *
194
- * @param string $postimage URL of the thumbnail image
195
- * @param int $thumb_width Thumbnail width
196
- * @param int $thumb_height Thumbnail height
197
- * @param boolean $thumb_timthumb Enable timthumb?
198
- * @param int $thumb_timthumb_q Quality of timthumb thumbnail.
199
- * @param object $result Post Object
200
- */
201
- $postimage = apply_filters( 'crp_postimage', $postimage, $args['thumb_width'], $args['thumb_height'], $thumb_timthumb, $thumb_timthumb_q, $result );
202
-
203
  if ( is_ssl() ) {
204
  $postimage = preg_replace( '~http://~', 'https://', $postimage );
205
  }
@@ -242,7 +223,13 @@ function crp_get_the_post_thumbnail( $args = array() ) {
242
  $output .= crp_get_image_html( $postimage, $attr );
243
 
244
  if ( function_exists( 'wp_img_tag_add_srcset_and_sizes_attr' ) ) {
245
- $output = wp_img_tag_add_srcset_and_sizes_attr( $output, 'crp_thumbnail', $attachment_id );
 
 
 
 
 
 
246
  }
247
 
248
  if ( function_exists( 'wp_img_tag_add_loading_attr' ) ) {
90
  $postimage = get_post_meta( $result->ID, $args['thumb_meta'], true );
91
  $pick = 'meta';
92
  if ( $postimage ) {
93
+ $attachment_id = crp_get_attachment_id_from_url( $postimage );
94
 
95
+ $postthumb = wp_get_attachment_image_src( $attachment_id, array( $args['thumb_width'], $args['thumb_height'] ) );
96
  if ( false !== $postthumb ) {
97
  $postimage = $postthumb[0];
98
  $pick .= 'correct';
135
  }
136
  $pick = 'first';
137
  if ( $postimage ) {
138
+ $attachment_id = crp_get_attachment_id_from_url( $postimage );
139
 
140
+ $postthumb = wp_get_attachment_image_src( $attachment_id, array( $args['thumb_width'], $args['thumb_height'] ) );
141
  if ( false !== $postthumb ) {
142
  $postimage = $postthumb[0];
143
  $pick .= 'correct';
181
  */
182
  $postimage = apply_filters( 'crp_thumb_url', $postimage, $args['thumb_width'], $args['thumb_height'], $result );
183
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
184
  if ( is_ssl() ) {
185
  $postimage = preg_replace( '~http://~', 'https://', $postimage );
186
  }
223
  $output .= crp_get_image_html( $postimage, $attr );
224
 
225
  if ( function_exists( 'wp_img_tag_add_srcset_and_sizes_attr' ) ) {
226
+ if ( empty( $attachment_id ) ) {
227
+ $attachment_id = crp_get_attachment_id_from_url( $postimage );
228
+ }
229
+
230
+ if ( ! empty( $attachment_id ) ) {
231
+ $output = wp_img_tag_add_srcset_and_sizes_attr( $output, 'crp_thumbnail', $attachment_id );
232
+ }
233
  }
234
 
235
  if ( function_exists( 'wp_img_tag_add_loading_attr' ) ) {
readme.txt CHANGED
@@ -2,7 +2,7 @@
2
  Tags: related posts, related, related articles, contextual related posts, similar posts, related posts widget
3
  Contributors: webberzone, Ajay
4
  Donate link: https://ajaydsouza.com/donate/
5
- Stable tag: 3.0.2
6
  Requires at least: 5.0
7
  Tested up to: 5.6
8
  Requires PHP: 5.6
@@ -174,6 +174,17 @@ You can insert the related posts anywhere in your post using the `[crp]` shortco
174
 
175
  == Changelog ==
176
 
 
 
 
 
 
 
 
 
 
 
 
177
  = 3.0.2 =
178
 
179
  * Bug fixes:
@@ -188,8 +199,6 @@ You can insert the related posts anywhere in your post using the `[crp]` shortco
188
 
189
  = 3.0.0 =
190
 
191
- Release post: [https://webberzone.com/blog/contextual-related-posts-v3-0-0/](https://webberzone.com/blog/contextual-related-posts-v3-0-0/)
192
-
193
  * Features:
194
  * New CRP_Query class for fetching related posts. This replaces `get_crp_posts_id()` which will be deprecated in a future version
195
  * CRP Thumbnails now include the `loading="lazy"` attribute added in WordPress 5.5
@@ -218,5 +227,5 @@ For the changelog of earlier versions, please refer to the separate changelog.tx
218
 
219
  == Upgrade Notice ==
220
 
221
- = 3.0.2 =
222
  Major release. Filters deprecated. Resave settings on upgrade. Please read the release post on https://webberzone.com
2
  Tags: related posts, related, related articles, contextual related posts, similar posts, related posts widget
3
  Contributors: webberzone, Ajay
4
  Donate link: https://ajaydsouza.com/donate/
5
+ Stable tag: 3.0.3
6
  Requires at least: 5.0
7
  Tested up to: 5.6
8
  Requires PHP: 5.6
174
 
175
  == Changelog ==
176
 
177
+ = 3.0.3 =
178
+
179
+ Release post: [https://webberzone.com/blog/contextual-related-posts-v3-0-0/](https://webberzone.com/blog/contextual-related-posts-v3-0-0/)
180
+
181
+ * Enhancement/Modifications:
182
+ * Grid style minimum width is now decided by the width of the thumbnail and long words are wrapped
183
+
184
+ * Bug fixes:
185
+ * Selecting No style created a 404 error
186
+ * Fixed issue with $attachment_id not being declared in some cases
187
+
188
  = 3.0.2 =
189
 
190
  * Bug fixes:
199
 
200
  = 3.0.0 =
201
 
 
 
202
  * Features:
203
  * New CRP_Query class for fetching related posts. This replaces `get_crp_posts_id()` which will be deprecated in a future version
204
  * CRP Thumbnails now include the `loading="lazy"` attribute added in WordPress 5.5
227
 
228
  == Upgrade Notice ==
229
 
230
+ = 3.0.3 =
231
  Major release. Filters deprecated. Resave settings on upgrade. Please read the release post on https://webberzone.com