Skip to content

Commit

Permalink
major revamp for version 2
Browse files Browse the repository at this point in the history
  • Loading branch information
acekyd committed Nov 5, 2016
1 parent 1accfb7 commit e66ac49
Show file tree
Hide file tree
Showing 4 changed files with 64 additions and 16 deletions.
7 changes: 7 additions & 0 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
17 changes: 17 additions & 0 deletions admin/partials/display-medium-posts-admin-display.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,21 @@

<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>

<h4>Advanced Usage and Customization</h4>
<p>There are additional features that can be implemented using Display Medium Posts : </p>
<ul>
<li><b>handle:</b> This is the user's medium handle e.g @acekyd <i>(Required)</i></li>
<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>
<li><b>display:</b> This is the amount of posts that should be displayed at a time e.g display=3</li>
<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>
<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>
</ul>

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

</div>
50 changes: 40 additions & 10 deletions display-medium-posts.php
Original file line number Diff line number Diff line change
Expand Up @@ -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+
Expand Down Expand Up @@ -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);</x>", "", $data);
Expand All @@ -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);
}

?>
<div id="display-medium-owl-demo" class="display-medium-owl-carousel">
<?php foreach($items as $item) { ?>
<div>
<img data-src="<?php echo $item['image']; ?>" class="lazyOwl">
<div class="display-medium-item">
<a href="<?php echo $item['url']; ?>">
<p class="details-title"><?php echo $item['title']; ?></p>
<img data-src="<?php echo $item['image']; ?>" class="lazyOwl">
<p class="display-medium-title details-title"><?php echo $item['title']; ?></p>
</a>
<p>
<p class="display-medium-subtitle">
<?php echo $item['subtitle']; ?>
</p>
<p>
<?php echo $item['date']; ?> / <?php echo $item['duration']; ?>min read.
<a href="<?php echo $item['url']; ?>" class="text-right">Read More</a>
<p class="display-medium-date-read">
<?php echo "<span class='display-medium-date'>".$item['date']."</span>"; ?> / <?php echo "<span class='display-medium-readtime'>".$item['duration']."min read</span>"; ?>.
<a href="<?php echo $item['url']; ?>" class="text-right display-medium-readmore">Read More</a>
</p>
</div>

<?php } ?>
</div>
<script type="text/javascript">
function initializeOwl(count) {
jQuery(".display-medium-owl-carousel").owlCarousel({
items: count,
lazyLoad : true,
});
}
</script>
<script>initializeOwl(<?php echo $display; ?>);</script>

<?php
}
add_shortcode('display_medium_posts', 'posts_display');
Expand Down
6 changes: 0 additions & 6 deletions public/js/display-medium-posts-public.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,4 @@
* Although scripts in the WordPress core, Plugins and Themes may be
* practising this, we should strive to set a better example in our own work.
*/

$(".display-medium-owl-carousel").owlCarousel({
items: 3,
lazyLoad : true,
});

})( jQuery );

0 comments on commit e66ac49

Please sign in to comment.