From e66ac49bed1c9d7ba7d1df4678c08bef753fcdc8 Mon Sep 17 00:00:00 2001 From: Abati Adewale Date: Sat, 5 Nov 2016 11:51:45 +0100 Subject: [PATCH] major revamp for version 2 --- README.txt | 7 +++ .../display-medium-posts-admin-display.php | 17 +++++++ display-medium-posts.php | 50 +++++++++++++++---- public/js/display-medium-posts-public.js | 6 --- 4 files changed, 64 insertions(+), 16 deletions(-) diff --git a/README.txt b/README.txt index f5c79d2..bc73db6 100755 --- a/README.txt +++ b/README.txt @@ -41,6 +41,13 @@ Nothing at the moment. 2. Displayed latest medium posts on page. == Changelog == +Version 2.0.0 +* Specify tags and css classes to allow users customize post display +* Added option to specify total number of posts to be fetched +* Added option to specify post offsets +* Fixed broken images +* Added option to specify custom user default images for broken images +* Added option to customize number of posts to be in view in the carousel at a time Version 1.0.0. * Display Posts in carousel \ No newline at end of file diff --git a/admin/partials/display-medium-posts-admin-display.php b/admin/partials/display-medium-posts-admin-display.php index 6da316c..e6cdea3 100755 --- a/admin/partials/display-medium-posts-admin-display.php +++ b/admin/partials/display-medium-posts-admin-display.php @@ -24,4 +24,21 @@

To use this plugin on any page/post, add shortcode with user handle e.g [display_medium_posts handle="@username"]

+

Advanced Usage and Customization

+

There are additional features that can be implemented using Display Medium Posts :

+ + +

+ An example of a full use of the plugin is as follows:
+ + [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] + +

+ \ No newline at end of file diff --git a/display-medium-posts.php b/display-medium-posts.php index c03c47d..84171a1 100755 --- a/display-medium-posts.php +++ b/display-medium-posts.php @@ -16,7 +16,7 @@ * Plugin Name: Display Medium Posts * Plugin URI: https://github.com/acekyd/display-medium-posts * Description: Display Medium Posts is a wordpress plugin that allows users display posts from medium.com on any part of their website. - * Version: 1.0.0 + * Version: 2.0.0 * Author: AceKYD * Author URI: http://www.acekyd.com * License: GPL-2.0+ @@ -76,12 +76,16 @@ function run_display_medium_posts() { // Example 1 : WP Shortcode to display form on any page or post. function posts_display($atts){ - $a = shortcode_atts(array('handle'=>'-1'), $atts); + $a = shortcode_atts(array('handle'=>'-1', 'default_image'=>'http://i.imgur.com/p4juyuT.png', 'display' => 3, 'offset' => 0, 'total' => 10), $atts); // No ID value if(strcmp($a['handle'], '-1') == 0){ return ""; } $handle=$a['handle']; + $default_image = $a['default_image']; + $display = $a['display']; + $offset = $a['offset']; + $total = $a['total']; $data = file_get_contents("https://medium.com/".$handle."/latest?format=json"); $data = str_replace("])}while(1);", "", $data); @@ -97,32 +101,58 @@ function posts_display($atts){ $items[$count]['title'] = $post->title; $items[$count]['url'] = 'https://medium.com/'.$handle.'/'.$post->uniqueSlug; $items[$count]['subtitle'] = $post->virtuals->snippet; - $items[$count]['image'] = 'http://cdn-images-1.medium.com/max/500/'.$post->virtuals->previewImage->imageId; + if(!empty($post->virtuals->previewImage->imageId)) + { + $image = 'http://cdn-images-1.medium.com/max/500/'.$post->virtuals->previewImage->imageId; + } + else { + $image = $default_image; + } + $items[$count]['image'] = $image; $items[$count]['duration'] = round($post->virtuals->readingTime); $items[$count]['date'] = $post->virtuals->createdAtRelative; $count++; } + if($offset) + { + $items = array_slice($items, $offset); + } + + if(count($items) > $total) + { + $items = array_slice($items, 0, $total); + } ?>