当前位置: 首页>>代码示例>>PHP>>正文


PHP get_attachment_link函数代码示例

本文整理汇总了PHP中get_attachment_link函数的典型用法代码示例。如果您正苦于以下问题:PHP get_attachment_link函数的具体用法?PHP get_attachment_link怎么用?PHP get_attachment_link使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


在下文中一共展示了get_attachment_link函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: attachment_toolbox

function attachment_toolbox($size = thumbnail, $type = 'house', $gallcount = '0', $ulClass = '', $emptyMsg = '')
{
    $images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order'));
    $count = 0;
    $out = '<ul class="' . $ulClass . '">';
    foreach ($images as $image) {
        $attimg = wp_get_attachment_image_src($image->ID, $size);
        $attimgurl = $attimg[0];
        $atturl = wp_get_attachment_url($image->ID);
        $attlink = get_attachment_link($image->ID);
        $postlink = get_permalink($image->post_parent);
        $atttitle = apply_filters('the_title', $image->post_title);
        $attcontent = $image->post_content;
        $attimgtype = get_post_meta($image->ID, "_mySelectBox", true);
        $imglink = $image->guid;
        if ($attimgtype == $type) {
            $count++;
            $out .= '<li><a href=' . $imglink . ' rel="prettyPhoto[gallery' . $gallcount . ']"><img class="primary" src="' . $attimgurl . '"/></a></li>';
        }
    }
    $out .= '</ul>';
    if ($count > 0) {
        echo $out;
    } else {
        echo $emptyMsg;
    }
    return $count;
}
开发者ID:jayfresh,项目名称:SweetSpot,代码行数:28,代码来源:functions.php

示例2: guiabsn_shortcode_photo_gallery

/** Show Photo gallery shortcode
 * [photo-gallery]
 */
function guiabsn_shortcode_photo_gallery($atts)
{
    global $post;
    extract(shortcode_atts(array('size' => 'photography'), $atts));
    $_attachments = get_posts(array('post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'post_parent' => $post->ID, 'order' => 'ASC', 'orderby' => 'menu_order ID'));
    // return false when invalid
    if (!count($_attachments)) {
        return false;
    }
    $output = '';
    $group_class = 'phogal-' . $post->ID;
    $output .= '<ul id="pg-thumb-list" class="pg-thumb-list">' . "\r\n";
    foreach ($_attachments as $key => $val) {
        $img_thumb = wp_get_attachment_image_src($val->ID, $size, false);
        $img_full_url = $val->guid;
        $output .= '<li id="thumb-' . $val->ID . '">';
        $output .= '<div class="pg-thumb-content">';
        $output .= '<a class="popup-img ' . $group_class . '" rel="' . $group_class . '" title="' . $val->post_title . '" href="' . get_attachment_link($val->ID) . '" data-url="' . $img_full_url . '"><img class="pt-thumb-image" src="' . $img_thumb[0] . '" alt="" title="" /></a>';
        $output .= '</div>';
        $output .= '</li>' . "\r\n";
    }
    $output .= '</ul>' . "\r\n";
    // fancybox
    if (count($_attachments)) {
        guiabsn_scripts_fancybox();
        $output .= '<script type="text/javascript">' . "\r\n" . '$(document).ready(function() {' . "\r\n" . '$("a[rel=\'' . $group_class . '\']").fancybox({ ' . "\r\n" . 'scrolling: "no", ' . "\r\n" . 'centerOnScroll: "true" ' . "\r\n" . '});' . "\r\n" . '});' . "\r\n" . '</script>' . "\r\n";
    }
    return $output;
}
开发者ID:nevertry,项目名称:guiabsn,代码行数:32,代码来源:custom-shortcodes.php

示例3: cw_magazine_the_attached_image

/**
 * Prints the attached image with a link to the next attached image.
 */
function cw_magazine_the_attached_image()
{
    $post = get_post();
    $attachment_size = apply_filters('underscore_attachment_size', array(1200, 1200));
    $next_attachment_url = wp_get_attachment_url();
    /**
     * Grab the IDs of all the image attachments in a gallery so we can get the
     * URL of the next adjacent image in a gallery, or the first image (if
     * we're looking at the last image in a gallery), or, in a gallery of one,
     * just the link to that image file.
     */
    $attachment_ids = get_posts(array('post_parent' => $post->post_parent, 'fields' => 'ids', 'numberposts' => -1, 'post_status' => 'inherit', 'post_type' => 'attachment', 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order ID'));
    // If there is more than 1 attachment in a gallery...
    if (count($attachment_ids) > 1) {
        foreach ($attachment_ids as $attachment_id) {
            if ($attachment_id == $post->ID) {
                $next_id = current($attachment_ids);
                break;
            }
        }
        // get the URL of the next image attachment...
        if ($next_id) {
            $next_attachment_url = get_attachment_link($next_id);
        } else {
            $next_attachment_url = get_attachment_link(array_shift($attachment_ids));
        }
    }
    printf('<a href="%1$s" title="%2$s" rel="attachment">%3$s</a>', esc_url($next_attachment_url), the_title_attribute(array('echo' => false)), wp_get_attachment_image($post->ID, $attachment_size));
}
开发者ID:nguyenvanvu,项目名称:bds,代码行数:32,代码来源:template-tags.php

示例4: get_permalink

function get_permalink($id = 0)
{
    $rewritecode = array('%year%', '%monthnum%', '%day%', '%hour%', '%minute%', '%second%', '%postname%', '%post_id%', '%category%', '%author%', '%pagename%');
    $post =& get_post($id);
    if ($post->post_status == 'static') {
        return get_page_link($post->ID);
    } elseif ($post->post_status == 'attachment') {
        return get_attachment_link($post->ID);
    }
    $permalink = get_settings('permalink_structure');
    if ('' != $permalink && 'draft' != $post->post_status) {
        $unixtime = strtotime($post->post_date);
        $category = '';
        if (strstr($permalink, '%category%')) {
            $cats = get_the_category($post->ID);
            $category = $cats[0]->category_nicename;
            if ($parent = $cats[0]->category_parent) {
                $category = get_category_parents($parent, FALSE, '/', TRUE) . $category;
            }
        }
        $authordata = get_userdata($post->post_author);
        $author = $authordata->user_nicename;
        $date = explode(" ", date('Y m d H i s', $unixtime));
        $rewritereplace = array($date[0], $date[1], $date[2], $date[3], $date[4], $date[5], $post->post_name, $post->ID, $category, $author, $post->post_name);
        return apply_filters('post_link', get_settings('home') . str_replace($rewritecode, $rewritereplace, $permalink), $post);
    } else {
        // if they're not using the fancy permalink option
        $permalink = get_settings('home') . '/?p=' . $post->ID;
        return apply_filters('post_link', $permalink, $post);
    }
}
开发者ID:staylor,项目名称:develop.svn.wordpress.org,代码行数:31,代码来源:template-functions-links.php

示例5: test_wp_ajax_send_attachment_to_editor_should_return_a_link

 /**
  * @ticket 36578
  */
 public function test_wp_ajax_send_attachment_to_editor_should_return_a_link()
 {
     // Become an administrator
     $post = $_POST;
     $user_id = self::factory()->user->create(array('role' => 'administrator', 'user_login' => 'user_36578_administrator', 'user_email' => 'user_36578_administrator@example.com'));
     wp_set_current_user($user_id);
     $_POST = array_merge($_POST, $post);
     $filename = DIR_TESTDATA . '/formatting/entities.txt';
     $contents = file_get_contents($filename);
     $upload = wp_upload_bits(basename($filename), null, $contents);
     $attachment = $this->_make_attachment($upload);
     // Set up a default request
     $_POST['nonce'] = wp_create_nonce('media-send-to-editor');
     $_POST['html'] = 'Bar Baz';
     $_POST['post_id'] = 0;
     $_POST['attachment'] = array('id' => $attachment, 'post_title' => 'Foo bar', 'url' => get_attachment_link($attachment));
     // Make the request
     try {
         $this->_handleAjax('send-attachment-to-editor');
     } catch (WPAjaxDieContinueException $e) {
         unset($e);
     }
     // Get the response.
     $response = json_decode($this->_last_response, true);
     $expected = sprintf('<a href="%s" rel="attachment wp-att-%d">Foo bar</a>', get_attachment_link($attachment), $attachment);
     // Ensure everything is correct
     $this->assertTrue($response['success']);
     $this->assertEquals($expected, $response['data']);
 }
开发者ID:atimmer,项目名称:wordpress-develop-mirror,代码行数:32,代码来源:Attachments.php

示例6: tc_modify_attachment_link

 /**
  * Add an optional rel="tc-fancybox[]" attribute to all images embedded in a post gallery
  * Based on the original WP function
  * @package Customizr
  * @since Customizr 3.0.5
  *
  */
 function tc_modify_attachment_link($markup, $id, $size, $permalink, $icon, $text)
 {
     if (!$this->tc_is_gallery_enabled()) {
         return $markup;
     }
     $tc_fancybox = esc_attr(TC_utils::$inst->tc_opt('tc_gallery_fancybox'));
     $tc_gallery_fancybox = apply_filters('tc_gallery_fancybox', esc_attr(TC_utils::$inst->tc_opt('tc_gallery_fancybox') && $tc_fancybox), $id);
     if ($tc_gallery_fancybox == 1 && $permalink == false) {
         $id = intval($id);
         $_post = get_post($id);
         if (empty($_post) || 'attachment' != $_post->post_type || !($url = wp_get_attachment_url($_post->ID))) {
             return __('Missing Attachment', 'customizr');
         }
         if ($permalink) {
             $url = get_attachment_link($_post->ID);
         }
         $post_title = esc_attr($_post->post_title);
         if ($text) {
             $link_text = $text;
         } elseif ($size && 'none' != $size) {
             $link_text = wp_get_attachment_image($id, $size, $icon);
         } else {
             $link_text = '';
         }
         if (trim($link_text) == '') {
             $link_text = $_post->post_title;
         }
         $markup = '<a class="grouped_elements" rel="tc-fancybox-group" href="' . $url . '" title="' . $post_title . '">' . $link_text . '</a>';
     }
     return $markup;
 }
开发者ID:umairriaz90,项目名称:Daschug1,代码行数:38,代码来源:class-content-gallery.php

示例7: get_attachment_link

 public function get_attachment_link($attachment_id, $orig_file)
 {
     if (isset($this->atts['link']) && $this->atts['link'] == 'file') {
         return $orig_file;
     } else {
         return get_attachment_link($attachment_id);
     }
 }
开发者ID:ugurozer,项目名称:little,代码行数:8,代码来源:tiled-gallery.php

示例8: network_shared_media_media_upload

function network_shared_media_media_upload()
{
    global $blog_id, $post;
    if (isset($_POST['send'])) {
        $nsm_blog_id = (int) $_GET['blog_id'];
        reset($_POST['send']);
        $nsm_send_id = (int) key($_POST['send']);
    }
    /* copied from wp-admin/inculdes/ajax-actions.php wp_ajax_send_attachment_to_editor() */
    if (isset($nsm_blog_id) && isset($nsm_send_id)) {
        switch_to_blog($nsm_blog_id);
        if (!current_user_can('upload_files')) {
            $current_blog_name = get_bloginfo('name');
            restore_current_blog();
            wp_die(__('You do not have permission to upload files to site: ') . $current_blog_name);
        }
        $attachment = wp_unslash($_POST['attachments'][$nsm_send_id]);
        $id = $nsm_send_id;
        if (!($post = get_post($id))) {
            wp_send_json_error();
        }
        if ('attachment' != $post->post_type) {
            wp_send_json_error();
        }
        $rel = $url = '';
        $html = $title = isset($attachment['post_title']) ? $attachment['post_title'] : '';
        if (!empty($attachment['url'])) {
            $url = $attachment['url'];
            if (strpos($url, 'attachment_id') || get_attachment_link($id) == $url) {
                $rel = ' rel="attachment wp-att-' . $id . '"';
            }
            $html = '<a href="' . esc_url($url) . '"' . $rel . '>' . $html . '</a>';
        }
        if ('image' === substr($post->post_mime_type, 0, 5)) {
            $align = isset($attachment['align']) ? $attachment['align'] : 'none';
            $size = isset($attachment['image-size']) ? $attachment['image-size'] : 'medium';
            $alt = isset($attachment['image_alt']) ? $attachment['image_alt'] : '';
            $caption = isset($attachment['post_excerpt']) ? $attachment['post_excerpt'] : '';
            $title = '';
            // We no longer insert title tags into <img> tags, as they are redundant.
            $html = get_image_send_to_editor($id, $caption, $title, $align, $url, (bool) $rel, $size, $alt);
        } elseif ('video' === substr($post->post_mime_type, 0, 5) || 'audio' === substr($post->post_mime_type, 0, 5)) {
            global $wp_embed;
            $meta = get_post_meta($id, '_wp_attachment_metadata', true);
            $html = $wp_embed->shortcode($meta, $url);
        }
        /** This filter is documented in wp-admin/includes/media.php */
        $html = apply_filters('media_send_to_editor', $html, $id, $attachment);
        // replace wp-image-<id>, wp-att-<id> and attachment_<id>
        $html = preg_replace(array('#(caption id="attachment_)(\\d+")#', '#(wp-image-|wp-att-)(\\d+)#'), array(sprintf('${1}nsm_%s_${2}', esc_attr($nsm_blog_id)), sprintf('${1}nsm-%s-${2}', esc_attr($nsm_blog_id))), $html);
        if (isset($_POST['chromeless']) && $_POST['chromeless']) {
            // WP3.5+ media browser is identified by the 'chromeless' parameter
            exit($html);
        } else {
            return media_send_to_editor($html);
        }
    }
}
开发者ID:ryan2407,项目名称:Vision,代码行数:58,代码来源:network_shared_media.php

示例9: add_social_tags

function add_social_tags()
{
    global $post;
    $id = $post->ID;
    $title = get_bloginfo('name');
    $urlFotoShare = wp_get_attachment_url($id);
    $urlFace = get_attachment_link($id);
    $descp = '';
    echo "\n            <meta name='description' content='{$title}' />\n            <meta name='DC.title' content='{$title}' />\n            <meta name='geo.region' content='BR-PR' />\n            <meta name='geo.placename' content='Cianorte' />\n            <meta name='geo.position' content='' />\n            <meta name='ICBM' content='' />\n\n            <meta property='og:url' content='{$urlFotoShare}'>\n            <meta property='og:title' content='{$title}'>\n            <meta property='og:site_name' content='Fato Basico'>\n            <meta property='og:description' content='descrição: {$descp}'>\n            <meta property='og:image' content='{$urlFotoShare}'>\n            <meta property='og:image:type' content='image/jpg'>\n            <meta property='og:image:width' content='114'> \n            <meta property='og:image:height' content='114'>\n            <meta property='og:type' content='website'> \n        ";
}
开发者ID:poliondas,项目名称:wordpress-br,代码行数:10,代码来源:image.php

示例10: __construct

 public function __construct($attachment_image, $needs_attachment_link, $grayscale)
 {
     $this->image = $attachment_image;
     $this->grayscale = $grayscale;
     $this->image_title = $this->image->post_title;
     $this->image_alt = get_post_meta($this->image->ID, '_wp_attachment_image_alt', true);
     $this->orig_file = wp_get_attachment_url($this->image->ID);
     $this->link = $needs_attachment_link ? get_attachment_link($this->image->ID) : $this->orig_file;
     $this->img_src = add_query_arg(array('w' => $this->image->width, 'h' => $this->image->height, 'crop' => true), $this->orig_file);
 }
开发者ID:dtekcth,项目名称:datateknologer.se,代码行数:10,代码来源:tiled-gallery-item.php

示例11: widget

 /**
  * Outputs the content of the widget
  *
  * @param array $args
  * @param array $instance
  */
 public function widget($args, $instance)
 {
     // outputs the content of the widget
     echo $args['before_widget'];
     if (!empty($instance['title'])) {
         echo $args['before_title'] . apply_filters('widget_title', $instance['title']) . $args['after_title'];
     }
     $number_of_posts = -1;
     if (!empty($instance['show_number_files'])) {
         $number_of_posts = $instance['show_number_files'];
     }
     $orderby = 'date';
     if (!empty($instance['sort_parameter'])) {
         $orderby = $instance['sort_parameter'];
     }
     $order_direction = 'DESC';
     if (!empty($instance['sort_direction'])) {
         $order_direction = $instance['sort_direction'];
     }
     $exclude_ids = array();
     if (!empty($instance['exclude_ids'])) {
         $exclude_ids = $instance['exclude_ids'];
     }
     // TODO: get template choice. Echo css based on choice
     echo '<style>.list_mediafiles_box{';
     echo 'border: 1px solid #e2e2e2;';
     echo 'margin: 5px;';
     echo 'padding: 5px;';
     echo '} .list_mediafiles_box img{';
     echo 'max-width:100px;';
     echo '} </style>';
     $args = array('post_type' => 'attachment', 'numberposts' => $number_of_posts, 'post_status' => null, 'post_parent' => null, 'orderby' => $orderby, 'order' => $order_direction, 'exclude' => $exclude_ids);
     $attachments = get_posts($args);
     if ($attachments) {
         foreach ($attachments as $post) {
             echo '<div class="list_mediafiles_box">';
             setup_postdata($post);
             echo '<h4>' . get_the_title($post->ID) . '</h4>';
             switch ($post->post_mime_type) {
                 case 'image/jpeg':
                 case 'image/png':
                 case 'image/gif':
                     the_attachment_link($post->ID, false);
                     break;
                 default:
                     echo '<a href="' . get_attachment_link($post->ID) . '"><img src="' . wp_mime_type_icon($post->post_mime_type) . '"></a>';
             }
             echo '<span class="aligncenter" style="word-break:break-word;">';
             the_excerpt();
             echo '</span>';
             echo '</div>';
         }
     }
     //echo $args['after_widget'];
 }
开发者ID:klasske,项目名称:wp_list_mediafiles_widget,代码行数:61,代码来源:list_mediafiles.php

示例12: postimage

function postimage($size = medium)
{
    if ($images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => 5, 'post_mime_type' => 'image'))) {
        foreach ($images as $image) {
            $attachmenturl = get_attachment_link($image->ID);
            $attachmentimage = wp_get_attachment_image($image->ID, $size);
            echo '<a href="' . $attachmenturl . '" class="home-gallery-item" rel="lightbox">' . $attachmentimage . '</a>';
        }
    } else {
        echo "No Image";
    }
}
开发者ID:m-godefroid76,项目名称:devrestofactory,代码行数:12,代码来源:functions.php

示例13: mfrh_media_send_to_editor

function mfrh_media_send_to_editor($html, $attachment_id, $attachment)
{
    $post =& get_post($attachment_id);
    if (substr($post->post_mime_type, 0, 5) == 'image') {
        $url = wp_get_attachment_url($attachment_id);
        $align = !empty($attachment['align']) ? $attachment['align'] : 'none';
        $size = !empty($attachment['image-size']) ? $attachment['image-size'] : 'medium';
        $alt = !empty($attachment['image_alt']) ? $attachment['image_alt'] : '';
        $rel = $url == get_attachment_link($attachment_id);
        return get_image_send_to_editor($attachment_id, $attachment['post_excerpt'], $attachment['post_title'], $align, $url, $rel, $size, $alt);
    }
    return $html;
}
开发者ID:rudeone,项目名称:dp,代码行数:13,代码来源:media-file-renamer.php

示例14: attachment_toolbox

function attachment_toolbox($size = 'portfolio-image', $emptyMsg = 'EMPTY')
{
    $images = get_children(array('post_parent' => get_the_ID(), 'post_type' => 'attachment', 'numberposts' => -1, 'post_status' => null, 'post_mime_type' => 'image', 'order' => 'ASC', 'orderby' => 'menu_order'));
    $count = 0;
    $out = '<div class="gallery">';
    foreach ($images as $image) {
        // split thumbParams
        $params = get_post_meta($image->ID, '_thumbnailParams', true);
        $params = explode(',', $params);
        $leftOffset = $params[0];
        $topOffset = $params[1];
        $width = $params[2];
        // Other image meta
        $colour = get_post_meta($image->ID, '_thumbnailColour', true);
        $attimg = wp_get_attachment_image_src($image->ID, $size);
        $attimgurl = $attimg[0];
        $atturl = wp_get_attachment_url($image->ID);
        $attlink = get_attachment_link($image->ID);
        $postlink = get_permalink($image->post_parent);
        $atttitle = apply_filters('the_title', $image->post_title);
        $attcontent = $image->post_content;
        $imglink = $image->guid;
        $attimgalt = get_post_meta($image->ID, '_wp_attachment_image_alt', true);
        $out .= '<img ';
        if ($leftOffset) {
            $out .= "data-leftOffset='{$leftOffset}' ";
        }
        if ($topOffset) {
            $out .= "data-topOffset='{$topOffset}' ";
        }
        if ($height) {
            $out .= "data-height='{$height}' ";
        }
        if ($width) {
            $out .= "data-width='{$width}' ";
        }
        if ($colour) {
            $out .= "data-colour='{$colour}'";
        }
        $out .= 'class="portfolioImage" src="' . $attimgurl . '" alt="' . $attimgalt . '" title="' . $atttitle . '"/>';
        $count++;
    }
    $out .= '</div>';
    if ($count > 0) {
        echo $out;
    } else {
        echo $emptyMsg;
    }
    return $count;
}
开发者ID:Joshuwar,项目名称:J-J-Portfolio,代码行数:50,代码来源:functions.php

示例15: __construct

 /**
  * Constructs instance of Document.
  *
  * @param WP_Post $attachment Attachment object used to initalize fields.
  * @param DG_Gallery $gallery Instance of Gallery class.
  */
 public function __construct($attachment, $gallery)
 {
     // init general document data
     $this->gallery = $gallery;
     $this->description = wptexturize($attachment->post_content);
     $this->ID = $attachment->ID;
     $this->link = $gallery->linkToAttachmentPg() ? get_attachment_link($attachment->ID) : wp_get_attachment_url($attachment->ID);
     $this->title = wptexturize($attachment->post_title);
     $this->title_attribute = esc_attr(strip_tags($this->title));
     $this->path = get_attached_file($attachment->ID);
     $wp_filetype = wp_check_filetype_and_ext($this->path, basename($this->path));
     $this->extension = $wp_filetype['ext'];
     $this->size = size_format(filesize($this->path));
 }
开发者ID:githubhelp,项目名称:document-gallery,代码行数:20,代码来源:class-document.php


注:本文中的get_attachment_link函数示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。