Пример #1
0
/**
 * Display next or previous image link that has the same post parent.
 *
 * Retrieves the current attachment object from the $post global.
 *
 * @since 2.5.0
 *
 * @param bool $prev Optional. Default is true to display previous link, false for next.
 */
function adjacent_image_link($prev = true, $size = 'thumbnail', $text = false)
{
    global $post;
    $post = get_post($post);
    $attachments = array_values(get_children(array('post_parent' => $post->post_parent, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID')));
    foreach ($attachments as $k => $attachment) {
        if ($attachment->ID == $post->ID) {
            break;
        }
    }
    $k = $prev ? $k - 1 : $k + 1;
    if (isset($attachments[$k])) {
        echo nxt_get_attachment_link($attachments[$k]->ID, $size, true, false, $text);
    }
}
Пример #2
0
/**
 * Wrap attachment in <<p>> element before content.
 *
 * @since 2.0.0
 * @uses apply_filters() Calls 'prepend_attachment' hook on HTML content.
 *
 * @param string $content
 * @return string
 */
function prepend_attachment($content)
{
    global $post;
    if (empty($post->post_type) || $post->post_type != 'attachment') {
        return $content;
    }
    $p = '<p class="attachment">';
    // show the medium sized image representation of the attachment if available, and link to the raw file
    $p .= nxt_get_attachment_link(0, 'medium', false);
    $p .= '</p>';
    $p = apply_filters('prepend_attachment', $p);
    return "{$p}\n{$content}";
}