mgsisk
1/28/2017 - 4:19 AM

Webcomic Featured Image Shortcode

Webcomic Featured Image Shortcode

<?php

function get_webcomic_featured_image($relation = 'random', $size = 'post-thumbnail', $attr = '', $collection = '') {
  if (!$collection) {
    $collection = get_webcomic_collection();
  }
  
  $comic = WebcomicTag::get_relative_webcomic($relation, '', '', '', $collection);
  
  if (!$comic) {
    return '';
  }
  
  return get_the_post_thumbnail($comic->ID, $size, $attr);
}

add_shortcode('webcomic_featured_image', function ($atts, $content, $name) {
  $args = shortcode_atts([
    'relation' => 'random',
    'size' => 'post-thumbnail',
    'atts' => '',
    'collection' => ''
  ], $atts, $name);

  return get_webcomic_featured_image($args['relation'], $args['size'], $args['atts'], $args['collection']);
});

/*
===== EXAMPLE =====

[last_webcomic_link collection="webcomic1"][webcomic_featured_image relation="last" collection="webcomic1"][/last_webcomic_link]
*/