/** * navis_image_shortcode(): renders caption shortcodes with our layout * and credit field. */ function caption_shortcode($text, $atts, $content) { $atts = shortcode_atts(array('id' => '', 'align' => 'alignnone', 'width' => '', 'credit' => '', 'caption' => ''), $atts); $atts = apply_filters('navis_image_layout_defaults', $atts); extract($atts); if ($id && !$credit) { $post_id = str_replace('attachment_', '', $id); $creditor = navis_get_media_credit($post_id); $credit = !empty($creditor) ? $creditor->to_string() : ''; } if ($id) { $id = 'id="' . esc_attr($id) . '" '; } // XXX: maybe remove module and image classes at some point $out = sprintf('<div %s class="wp-caption module image %s" style="max-width: %spx;">%s', $id, $align, $width, do_shortcode($content)); if ($credit) { $out .= sprintf('<p class="wp-media-credit">%s</p>', $credit); } if ($caption) { $out .= sprintf('<p class="wp-caption-text">%s</p>', $caption); } $out .= "</div>"; return $out; }
/** * * @uses global $post WP Post object */ function handle_slideshow($output, $attr) { /** * Grab attachments */ global $post; $this->slideshows += 1; // jQuery slides plugin, available at http://slidesjs.com/ $slides_src = get_template_directory_uri() . '/lib/navis-slideshows/vendor/slick/slick.min.js'; wp_enqueue_script('jquery-slick', $slides_src, array('jquery'), '3.0', true); // our custom js $show_src = get_template_directory_uri() . '/lib/navis-slideshows/js/navis-slideshows.js'; wp_enqueue_script('navis-slideshows', $show_src, array('jquery-slick'), '0.1', true); $attr = shortcode_atts(array('order' => 'ASC', 'orderby' => 'menu_order ID', 'id' => $post->ID, 'itemtag' => 'dl', 'icontag' => 'dt', 'captiontag' => 'dd', 'columns' => 3, 'size' => 'thumbnail', 'link' => 'file', 'ids' => ''), $attr); $id = intval($attr['id']); $order = $attr['order'] == 'ASC' ? 'ASC' : 'DESC'; if (isset($attr['orderby'])) { $attr['orderby'] = sanitize_sql_orderby($attr['orderby']); if (!$attr['orderby']) { unset($attr['orderby']); } } $size = sanitize_key($attr['size']); $ids = array_map('intval', explode(',', $attr['ids'])); // XXX: this could be factored out to a common function for getting // a post's images //if no IDs set, get attached posts if (empty($ids)) { $attachments = get_children(array('post_parent' => $id, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => $order, 'orderby' => $orderby, 'numberposts' => 200)); } else { $raw_attachments = get_posts(array('post__in' => $ids, 'post_type' => 'attachment', 'post_mime_type' => 'image', 'numberposts' => 200)); // If attachments are returned, put them into the array in the order specified if (is_array($raw_attachments)) { foreach ($ids as $id) { foreach ($raw_attachments as $attachment) { if ($id == $attachment->ID) { $attachments[(string) $id] = $attachment; } } } } } if (empty($attachments)) { return ''; } if (is_feed()) { $output = "\n"; foreach ($attachments as $id => $attachment) { $output .= wp_get_attachment_link($id, $size, true) . "\n"; } return $output; } $postid = $post->ID ? $post->ID : rand(0, 10000); $plink = get_permalink(); $post_html_id = $postid . "-" . md5($post->ID . $post->post_title . $post->post_content . $this->slideshows); $output .= ' <div id="slides-' . esc_attr($post_html_id) . '" class="navis-slideshow">'; /*-- Add images --*/ $count = 0; $total = count($attachments); foreach ($attachments as $id => $attachment) { $count++; // Credit functionality provided by navis-media-credit plugin $credit = ''; if (function_exists('navis_get_media_credit')) { $creditor = navis_get_media_credit($id); $credit = $creditor->to_string(); } $caption = $attachment->post_excerpt; $slidediv = $post_html_id . '-slide' . $count; $img_url = wp_get_attachment_url($id); $output .= '<div id="' . esc_attr($slidediv) . '">'; $output .= '<img data-lazy="' . esc_url($img_url) . '" />'; if (!empty($credit)) { $output .= '<h6 class="credit">' . wp_kses_post($credit) . '</h6>'; } $slide_link = get_permalink($post) . '#' . $post_html_id . '/' . $count; $output .= '<h6 class="permalink"><a href="' . $slide_link . '" class="slide-permalink"><i class="icon-link"></i> ' . esc_attr(__('permalink', 'largo')) . '</a></h6>'; if (!empty($caption)) { $output .= '<p class="wp-caption-text">' . wp_kses_post($caption) . '</p>'; } $output .= '</div>'; } $output .= '</div>'; return $output; }