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


PHP acf_get_attachment函数代码示例

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


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

示例1: build_block_elements

 protected function build_block_elements()
 {
     // Subheader.
     $section_header_text = !empty($this->input['uploaded_files_header']) ? $this->input['uploaded_files_header'] : __('Available downloads', EXCHANGE_PLUGIN);
     $section_header_mods = array('type' => 'taped_header', 'colour' => exchange_slug_to_hex('blue-3'));
     $section_header = new SectionHeader($section_header_text, $this->element, $section_header_mods);
     $this->output .= $section_header->embed();
     // Paragraph.
     $paragraph_text = '<ul class="documentblock__file-list dont-break-out">';
     foreach ($this->input['add_file'] as $doc) {
         if (!is_numeric($doc['file'])) {
             continue;
         }
         if (function_exists('acf_get_attachment')) {
             $meta = acf_get_attachment($doc['file']);
         }
         if (empty($meta)) {
             continue;
         }
         $description = !empty($meta['description']) ? $meta['description'] : $meta['filename'];
         $paragraph_text .= '<li class="documentblock__file-list__item">';
         $paragraph_text .= '<a href="' . $meta['url'] . '" target="_blank">' . $description . '</a>';
         $paragraph_text .= '</li>';
     }
     $paragraph_text .= '</ul>';
     $paragraph = new Paragraph($paragraph_text, $this->element);
     $this->output .= $paragraph->embed();
 }
开发者ID:retrorism,项目名称:exchange-plugin,代码行数:28,代码来源:class-document-block.php

示例2: get_user_image

 /**
  * Get user image.
  *
  * @return object $image Image Pattern object.
  */
 private function get_user_image()
 {
     $image = $this->user_meta['user_image'][0];
     if (empty($image)) {
         return;
     }
     if (function_exists('acf_get_attachment')) {
         $input = acf_get_attachment($image);
         if (empty($input)) {
             return;
         }
         $image_mods = array('style' => 'rounded');
         $image_obj = new Image($input, $this->element, $image_mods);
         if (!$image_obj instanceof Image) {
             return;
         }
     }
     return $image_obj;
 }
开发者ID:retrorism,项目名称:exchange-plugin,代码行数:24,代码来源:class-contact-block.php

示例3: format_value

 function format_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         return $value;
     }
     // convert to int
     $value = intval($value);
     // format
     if ($field['return_format'] == 'url') {
         return wp_get_attachment_url($value);
     } elseif ($field['return_format'] == 'array') {
         return acf_get_attachment($value);
     }
     return $value;
 }
开发者ID:adnandot,项目名称:intenseburn,代码行数:16,代码来源:image.php

示例4: format_value

 function format_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         // return false as $value may be '' (from DB) which doesn't make much sense
         return false;
     }
     // get posts
     $posts = acf_get_posts(array('post_type' => 'attachment', 'post__in' => $value));
     // update value to include $post
     foreach (array_keys($posts) as $i) {
         $posts[$i] = acf_get_attachment($posts[$i]);
     }
     // return
     return $posts;
 }
开发者ID:TMBR,项目名称:johnjohn,代码行数:16,代码来源:gallery.php

示例5: format_value

 function format_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         return false;
     }
     // get posts
     $posts = $this->get_attachments($value);
     // update value to include $post
     foreach (array_keys($posts) as $i) {
         $posts[$i] = acf_get_attachment($posts[$i]);
     }
     // return
     return $posts;
 }
开发者ID:rmikeska,项目名称:ushipnetwork,代码行数:15,代码来源:gallery.php

示例6: format_value

 function format_value($value, $post_id, $field)
 {
     // bail early if no value
     if (empty($value)) {
         return $value;
     }
     // force value to array
     $value = acf_force_type_array($value);
     // convert values to int
     $value = array_map('intval', $value);
     // load posts in 1 query to save multiple DB calls from following code
     $posts = get_posts(array('posts_per_page' => -1, 'post_type' => 'attachment', 'post_status' => 'any', 'post__in' => $value, 'orderby' => 'post__in'));
     // reset value
     $value = array();
     // populate value
     foreach ($posts as $post) {
         $value[] = acf_get_attachment($post);
     }
     // return
     return $value;
 }
开发者ID:tofubuddha,项目名称:example,代码行数:21,代码来源:gallery.php

示例7: elseif

 if ($boxColor == 'Light Blue') {
     $btnClass = 'btn-blue';
 } elseif ($boxColor == 'Yellow') {
     $btnClass = 'btn-yellow';
 } elseif ($boxColor == 'Red') {
     $btnClass = 'btn-red';
 } elseif ($boxColor == 'Green') {
     $btnClass = 'btn-green';
 } elseif ($boxColor == 'Purple') {
     $btnClass = 'btn-purple';
 } else {
     $btnClass = 'btn-dark-blue';
 }
 $image = get_field('button');
 if (!is_array($image)) {
     $image = acf_get_attachment($image);
 }
 if ($image != '') {
     $url = $image['url'];
     $title = $image['title'];
     $alt = $image['alt'];
     $caption = $image['caption'];
     $size = 'large';
     $thumb = $image['sizes'][$size];
     $width = $image['sizes'][$size . '-width'];
     $height = $image['sizes'][$size . '-height'];
 }
 $title = get_the_title();
 $santiTitle = sanitize_title_with_dashes($title);
 $link = $parentLink . 'services-pricing/pet-sitting-dog-walking/#' . $santiTitle;
 ?>
开发者ID:accrane,项目名称:Little-Friends-Pet-Sitting,代码行数:31,代码来源:page-home-care.php

示例8: exchange_create_image_id

/**
 * Create the image attachment and return the new media upload id.
 *
 * @author Joshua David Nelson, josh@joshuadnelson.com
 *
 * @see http://codex.wordpress.org/Function_Reference/wp_insert_attachment#Example
 *
 * @link https://joshuadnelson.com/programmatically-add-images-to-media-library/
 *
 * @param string $image_url The url to the image you're adding to the Media library.
 * @param int $parent_post_id Optional. Use to attach the media file to a specific post.
 */
function exchange_create_image_id($image_url, $parent_post_id = null)
{
    // Bail if the image url isn't valid.
    if (empty($image_url) || !esc_url($image_url)) {
        return false;
    }
    // Escape the url, just to be safe.
    $image_url = esc_url($image_url);
    // Cache info on the wp uploads dir.
    $wp_upload_dir = wp_get_upload_dir();
    $wp_upload_path = $wp_upload_dir['basedir'];
    // Get the file path.
    $path_array = explode('uploads', $image_url);
    // File base name, e.g. image.jpg.
    $file_base_name = basename($image_url);
    // Combine the two to get the uploaded file path.
    $uploaded_file_path = $wp_upload_path . $path_array[1];
    // Check the type of file. We'll use this as the 'post_mime_type'.
    $filetype = wp_check_filetype($file_base_name, null);
    // Error check.
    if (!empty($filetype) && is_array($filetype)) {
        // Create attachment title - basically, pull out the text.
        $post_title = preg_replace('/\\.[^.]+$/', '', $file_base_name);
        // Prepare an array of post data for the attachment.
        $attachment = array('guid' => $wp_upload_dir['url'] . '/' . basename($uploaded_file_path), 'post_mime_type' => $filetype['type'], 'post_title' => esc_attr($post_title), 'post_content' => '', 'post_status' => 'inherit');
        // Set the post parent id if there is one.
        if (!is_null($parent_post_id) && absint($parent_post_id)) {
            $attachment['post_parent'] = absint($parent_post_id);
        }
        // Insert the attachment.
        $attach_id = wp_insert_attachment($attachment, $uploaded_file_path);
        // Error check.
        if (!is_wp_error($attach_id)) {
            // Generate wp attachment meta data.
            if (file_exists(ABSPATH . 'wp-admin/includes/image.php') && file_exists(ABSPATH . 'wp-admin/includes/media.php')) {
                require_once ABSPATH . 'wp-admin/includes/image.php';
                require_once ABSPATH . 'wp-admin/includes/media.php';
                $attach_data = wp_generate_attachment_metadata($attach_id, $uploaded_file_path);
                wp_update_attachment_metadata($attach_id, $attach_data);
            }
            // End if file exists check.
            $attachment_acf = acf_get_attachment($attach_id);
        }
        return $attach_id;
    } else {
        return false;
    }
    // End if $filetype.
}
开发者ID:retrorism,项目名称:exchange-plugin,代码行数:61,代码来源:admin-gravity.php

示例9: get_acf_posts

 /**
  * get_acf_posts
  *
  * This function queries multiple posts and returns also all the Advanced Custom Fields data set saved in the posts meta.
  * Meta data is handled the same way as in the get_posts-function.
  *
  * @type	function
  * @date	20/3/2015
  * @since	0.0.1
  *
  * @param	[array]		$args 	Arguments to override the defaults defined in get_wp_query_defaults.
  * @return	[array]				array of posts as an associative array with acf fields and meta data
  */
 public static function get_acf_posts($args)
 {
     // Some redundancy, but we need these
     $defaults = self::get_wp_query_defaults();
     $options = array_merge($defaults, $args);
     extract($options);
     // Perform the basic query first
     self::get_posts($options);
     // Temporarily set 'query_object' to 'true'
     $args['query_object'] = true;
     self::get_posts($args);
     // Extend the posts with acf data
     if (is_array(self::$query->posts)) {
         // loop through posts and get all acf fields
         foreach (self::$query->posts as &$p) {
             $p->fields = get_fields($p->ID);
             if ($whole_fields) {
                 foreach ($p->fields as $name => &$field) {
                     $field = get_field_object($name, $p->ID, true);
                 }
             }
             // Add attachment image to post
             if (function_exists("acf_get_attachment")) {
                 $attachment_id = get_post_thumbnail_id($p->ID);
                 if ($attachment_id) {
                     $p->image = acf_get_attachment($attachment_id);
                 }
             }
         }
         // Maybe return the whole query object
         if ($query_object || false === $no_found_rows) {
             return self::$query;
         } else {
             return self::$query->posts;
         }
     } else {
         return false;
     }
 }
开发者ID:devgeniem,项目名称:dustpress,代码行数:52,代码来源:query.php

示例10: set_gallery

 protected function set_gallery()
 {
     if ($this->container->has_gallery) {
         return;
     }
     $unique_arrs = $this->get_gallery_from_acf();
     if (empty($unique_arrs) && 'story' === $this->container->type) {
         // Start over with a new gallery array to be filled with a query.
         $unique_arrs = array();
         $unique_ids = $this->get_gallery_from_query();
         if (empty($unique_ids)) {
             return;
         }
         foreach ($unique_ids as $img_id) {
             if (function_exists('acf_get_attachment')) {
                 $img_arr = acf_get_attachment($img_id);
                 if (!empty($img_arr)) {
                     $unique_arrs[] = $img_arr;
                 }
             }
         }
     }
     $gallery = $this->prepare_gallery_images($unique_arrs);
     if (empty($gallery)) {
         if ($this->container->has_video) {
             $this->container->has_gallery = true;
         }
     } else {
         $this->container->gallery = $gallery;
         $this->container->has_gallery = true;
     }
 }
开发者ID:retrorism,项目名称:exchange-plugin,代码行数:32,代码来源:class-controller-base.php


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