Skip to content

Commit e66ac49

Browse files
committed
major revamp for version 2
1 parent 1accfb7 commit e66ac49

File tree

4 files changed

+64
-16
lines changed

4 files changed

+64
-16
lines changed

README.txt

+7
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,13 @@ Nothing at the moment.
4141
2. Displayed latest medium posts on page.
4242

4343
== Changelog ==
44+
Version 2.0.0
45+
* Specify tags and css classes to allow users customize post display
46+
* Added option to specify total number of posts to be fetched
47+
* Added option to specify post offsets
48+
* Fixed broken images
49+
* Added option to specify custom user default images for broken images
50+
* Added option to customize number of posts to be in view in the carousel at a time
4451
Version 1.0.0.
4552

4653
* Display Posts in carousel

admin/partials/display-medium-posts-admin-display.php

+17
Original file line numberDiff line numberDiff line change
@@ -24,4 +24,21 @@
2424

2525
<p>To use this plugin on any page/post, add shortcode with user handle e.g <span style="color:red">[display_medium_posts handle="@username"]</span></p>
2626

27+
<h4>Advanced Usage and Customization</h4>
28+
<p>There are additional features that can be implemented using Display Medium Posts : </p>
29+
<ul>
30+
<li><b>handle:</b> This is the user's medium handle e.g @acekyd <i>(Required)</i></li>
31+
<li><b>default_image:</b> This is the url of default image that should show when post doesn't have a featured image e.g http://i.imgur.com/p4juyuT.png</li>
32+
<li><b>display:</b> This is the amount of posts that should be displayed at a time e.g display=3</li>
33+
<li><b>offset:</b> This is used when you don't want to display the most recent posts. You can specify the offset to skip the first number of items specified. Default is 0 e.g offset=2</li>
34+
<li><b>total:</b> This is used to specify the amount of posts to fetch. Maximum is 10. This is also useful if you just want to display a single item e.g total=1</li>
35+
</ul>
36+
37+
<p>
38+
An example of a full use of the plugin is as follows:<br>
39+
<b>
40+
[display_medium_posts handle="@acekyd" default_image="http://www.acekyd.com/wp-content/uploads/2014/11/IMG_20150731_220116.png" display=4 offset=2 total=10]
41+
</b>
42+
</p>
43+
2744
</div>

display-medium-posts.php

+40-10
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
* Plugin Name: Display Medium Posts
1717
* Plugin URI: https://github.com/acekyd/display-medium-posts
1818
* Description: Display Medium Posts is a wordpress plugin that allows users display posts from medium.com on any part of their website.
19-
* Version: 1.0.0
19+
* Version: 2.0.0
2020
* Author: AceKYD
2121
* Author URI: http://www.acekyd.com
2222
* License: GPL-2.0+
@@ -76,12 +76,16 @@ function run_display_medium_posts() {
7676

7777
// Example 1 : WP Shortcode to display form on any page or post.
7878
function posts_display($atts){
79-
$a = shortcode_atts(array('handle'=>'-1'), $atts);
79+
$a = shortcode_atts(array('handle'=>'-1', 'default_image'=>'http://i.imgur.com/p4juyuT.png', 'display' => 3, 'offset' => 0, 'total' => 10), $atts);
8080
// No ID value
8181
if(strcmp($a['handle'], '-1') == 0){
8282
return "";
8383
}
8484
$handle=$a['handle'];
85+
$default_image = $a['default_image'];
86+
$display = $a['display'];
87+
$offset = $a['offset'];
88+
$total = $a['total'];
8589

8690
$data = file_get_contents("https://medium.com/".$handle."/latest?format=json");
8791
$data = str_replace("])}while(1);</x>", "", $data);
@@ -97,32 +101,58 @@ function posts_display($atts){
97101
$items[$count]['title'] = $post->title;
98102
$items[$count]['url'] = 'https://medium.com/'.$handle.'/'.$post->uniqueSlug;
99103
$items[$count]['subtitle'] = $post->virtuals->snippet;
100-
$items[$count]['image'] = 'http://cdn-images-1.medium.com/max/500/'.$post->virtuals->previewImage->imageId;
104+
if(!empty($post->virtuals->previewImage->imageId))
105+
{
106+
$image = 'http://cdn-images-1.medium.com/max/500/'.$post->virtuals->previewImage->imageId;
107+
}
108+
else {
109+
$image = $default_image;
110+
}
111+
$items[$count]['image'] = $image;
101112
$items[$count]['duration'] = round($post->virtuals->readingTime);
102113
$items[$count]['date'] = $post->virtuals->createdAtRelative;
103114

104115
$count++;
105116
}
117+
if($offset)
118+
{
119+
$items = array_slice($items, $offset);
120+
}
121+
122+
if(count($items) > $total)
123+
{
124+
$items = array_slice($items, 0, $total);
125+
}
106126

107127
?>
108128
<div id="display-medium-owl-demo" class="display-medium-owl-carousel">
109129
<?php foreach($items as $item) { ?>
110-
<div>
111-
<img data-src="<?php echo $item['image']; ?>" class="lazyOwl">
130+
<div class="display-medium-item">
112131
<a href="<?php echo $item['url']; ?>">
113-
<p class="details-title"><?php echo $item['title']; ?></p>
132+
<img data-src="<?php echo $item['image']; ?>" class="lazyOwl">
133+
<p class="display-medium-title details-title"><?php echo $item['title']; ?></p>
114134
</a>
115-
<p>
135+
<p class="display-medium-subtitle">
116136
<?php echo $item['subtitle']; ?>
117137
</p>
118-
<p>
119-
<?php echo $item['date']; ?> / <?php echo $item['duration']; ?>min read.
120-
<a href="<?php echo $item['url']; ?>" class="text-right">Read More</a>
138+
<p class="display-medium-date-read">
139+
<?php echo "<span class='display-medium-date'>".$item['date']."</span>"; ?> / <?php echo "<span class='display-medium-readtime'>".$item['duration']."min read</span>"; ?>.
140+
<a href="<?php echo $item['url']; ?>" class="text-right display-medium-readmore">Read More</a>
121141
</p>
122142
</div>
123143

124144
<?php } ?>
125145
</div>
146+
<script type="text/javascript">
147+
function initializeOwl(count) {
148+
jQuery(".display-medium-owl-carousel").owlCarousel({
149+
items: count,
150+
lazyLoad : true,
151+
});
152+
}
153+
</script>
154+
<script>initializeOwl(<?php echo $display; ?>);</script>
155+
126156
<?php
127157
}
128158
add_shortcode('display_medium_posts', 'posts_display');

public/js/display-medium-posts-public.js

-6
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,4 @@
2828
* Although scripts in the WordPress core, Plugins and Themes may be
2929
* practising this, we should strive to set a better example in our own work.
3030
*/
31-
32-
$(".display-medium-owl-carousel").owlCarousel({
33-
items: 3,
34-
lazyLoad : true,
35-
});
36-
3731
})( jQuery );

0 commit comments

Comments
 (0)